Learning: Kubernetes (POD)

Karan Gupta
3 min readDec 5, 2020

--

As we continue to investigate the workings of Kubernetes one cannot get away from the need of understanding how a POD is created. In this tutorial, we will go through a set of things that need to happen before a Pod created. Let’s see what kind of things happen when we create the pod using the cli command that resembled below:

# before v1.18
kubectl run my-nginx --image nginx
# on & after v1.18
kubectl create deployment nginx --image nginx

kubectl run

When we run the above command using run to create the pod there are several steps that happen. It uses the Deployment Controller to initiate this process. We can look at the specification in order to learn how to do that using this official document. Deployment Controller is used for meeting following requirements:

  1. Since you can have more than 1 replica of your container, it creates a ReplicatSet Controller. ReplicatSet Controller is what that creates the pod and ensures it has the same number of pods running your container as you have asked it to do.
  2. Maybe you want to update the configs of your container application — this initiates a need to create a new ReplicaSet Controller. That is, declaring a new state of the pods by updating the pod spec template.
  3. Oops! There was a mistake in the deployment. We need to rollback to the previous version of the deployment.
  4. For more we can refer to the official doc.

Pod Creation

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

Let’s look at the above example that describe how nginx needs to be deployed in Kubernetes. We know that it ultimately needs to create a container running nginx on it. So let go ahead and do that.

When you “run” the command, it created the pod. It also creates more layers of abstraction on top of it.

The way it creates that pod was when we typed kubectl run, it created a Deployment.

When that Deployment was created, a ReplicaSet was created. The ReplicaSet’s job is to ensure that the number of pods we asked for are currently running. In this case, 3 because we that’s what we defined it in the configuration .spec.replicas in your PodSpecTemplate.

Conclusively, we can understand how the pods (your applications) are managed with respect to what is desired by the YAML configuration.

  • Deployment ensuring replication using ReplicaSet.
  • ReplicaSet ensuring the orders received from the deployment controller is adhered on all pods it manages.
  • Pods ensuring the your container application is functioning as you had coded and configured using perhaps docker-compose.yml.

--

--

Karan Gupta
Karan Gupta

Written by Karan Gupta

Just a curious developer, a proud uncle, a weightlifter, & your neighborhood yogi.

No responses yet