Kubernetes
Learn Kubernetes
3 Core Concepts

Kubernetes Core Concepts Guide 🚀

ETCD 📚

ETCDCTL Command Interaction

ETCDCTL can interact with the ETCD Server using two API versions: Version 2 and Version 3. By default, it is set to use Version 2. Each version has different sets of commands.

ETCDCTL Version 2 Commands:

  • etcdctl backup
  • etcdctl cluster-health
  • etcdctl mk
  • etcdctl mkdir
  • etcdctl set

ETCDCTL Version 3 Commands:

  • etcdctl snapshot save
  • etcdctl endpoint health
  • etcdctl get
  • etcdctl put

To set the right version of the API, set the environment variable ETCDCTL_API:

export ETCDCTL_API=3

Replication Controller (RC) 💾

Replica Set 📊

Deployments.yml 📄


Imperative CLI Commands 🛠️

Create an NGINX Pod

kubectl run nginx --image=nginx

Generate POD Manifest YAML file (-o yaml). Don't create it (--dry-run)

kubectl run nginx --image=nginx --dry-run=client -o yaml

Create a Deployment

kubectl create deployment --image=nginx nginx

Generate Deployment YAML file (-o yaml). Don't create it (--dry-run)

kubectl create deployment --image=nginx nginx --dry-run=client -o yaml

Generate Deployment YAML file (-o yaml). Don’t create it (--dry-run) and save it to a file

kubectl create deployment --image=nginx nginx --dry-run=client -o yaml > nginx-deployment.yaml

Make necessary changes to the file (e.g., adding more replicas) and then create the deployment:

kubectl create -f nginx-deployment.yaml

In Kubernetes version 1.19+, we can specify the --replicas option to create a deployment with 4 replicas:

kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml

Services 🛠️

Service Types

Cluster IP

Load Balancer


Namespaces 🏷️

Create a Namespace

A namespace is a logical grouping of resources.

Connecting to Servers in Different Nodes & Namespaces

To connect to the same namespace, we can use a service name of that resource to connect (e.g., mysql.connect("db-service")).

Pod Definition File

A pod definition file that will auto-create a pod in a specific namespace defined in the YAML label section (e.g., namespace: dev).

Switch to Another Namespace Permanently (from Default)

Resource Quota for Namespace

Limit the usage of resources in a specific namespace.


Imperative Commands for Services 🛠️

Create a Service Named redis-service of Type ClusterIP to Expose Pod redis on Port 6379

kubectl expose pod redis --port=6379 --name redis-service --dry-run=client -o yaml

(This will automatically use the pod's labels as selectors.)

Or

kubectl create service clusterip redis --tcp=6379:6379 --dry-run=client -o yaml

(This will not use the pod's labels as selectors, instead it will assume selectors as app=redis. You cannot pass in selectors as an option. Generate the file and modify the selectors before creating the service.)

Create a Service Named nginx of Type NodePort to Expose Pod nginx's Port 80 on Port 30080 on the Nodes

kubectl expose pod nginx --type=NodePort --port=80 --name=nginx-service --dry-run=client -o yaml

(This will automatically use the pod's labels as selectors, but you cannot specify the node port. Generate a definition file and then add the node port manually before creating the service with the pod.)

Or

kubectl create service nodeport nginx --tcp=80:80 --node-port=30080 --dry-run=client -o yaml

(This will not use the pod's labels as selectors.)

Both the above commands have their own challenges. While one cannot accept a selector, the other cannot accept a node port. I recommend going with the kubectl expose command. If you need to specify a node port, generate a definition file using the same command and manually input the node port before creating the service.


🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!