Kubernetes pods, It's all you know about.

Photo by Michael Jasmund on Unsplash

Pod is the smallest instance in Kubernetes that you are working with. This post will cover everything you need to learn about pods and how to deploy it.

What is a pod why not containers?

We use pods in k8s to deploy our application. Someone may ask why not to use containers in k8s and the answer is there are many types of containers such as docker, podman, LUX, containerd and many more hence pod act as a wrapper. We can have multiple containers inside the pod and most of the cases those might be supporting containers.

Let’s deploy a nginx server inside the cluster using kubectl run nginx --image=nginx . We can check the pod using kubectl get pods command.

But as a practice we use a file to deploy anything in k8s because in production environments we need to simplify the process. Following is a sample pod deployment file.

Any deployment file have 4 main fields which are,

  • apiVersion — define which k8s version that we are using. Ex — For pods we are using v1 and for Replicaset we use apps/v1
  • kind — What is the component that we are specifying in the file. Ex — Can be any component such as pod, service, replicaset, job etc.
  • metadata — This will include the meta information for the pod such as name or any additional information which can be mention under label.
  • spec — Component specification fall under this section and for the pod it define what is the image that we are using what ports are exposed.

Above pod can be deployed using kubectl apply -f pod-nginx-definition.yaml. After deploying we can get the pod information using kubectl describe pod nginx-server and it output following information.

If you need to remove the pod you created you can simply do that by kubectl delete pods nginx-server .

Please read kubernetes architecture post if you are not aware of it.


In k8s we usually deploy multiple instances of the same application which is known as replication. Replicas are made using replica sets in k8s and replica set is responsible of creating given number of replicas and maintain the number of replicas (If one crash replica set will create another pod).

Replica set help to provide high availability and load balancing. Following is a nginx replicaset which have 3 replicas.

  • apiVersion of the replicaset is apps/v1 .
  • kind is replicaset itself.
  • metadata are name and labels and labels can be any key value pairs.
  • In the spec there are 3 sections to be mentioned which are, replicas — number of instances that you need, selector — identify which pods are in the replicaset, template — define the pod.

Deployment of the replicaset can be done using kubectl apply -f <filename>.


Selector plays a major role, it tracks all the pods with the given label (In our case type=test-prod) and make sure there are corresponding number of replicas are available.

Ex — If there are already two pods which have the label type=test-prod then after apply above replica it will only create a one pod since the requirement is to have 3 and 2 are already there.


End of the day what you need to be done a deployment which can be done using k8s deployments. Deployment supports,

  • rolling updates — default deployment strategy.
  • recreate strategy.
  • rollbacks — undo to the last revision.

Let’s do a simple deployment and do some deployment updates and undo it.

Let’s apply the deployment file using kubectl apply -f nginx-first-deployment.yaml and you can view all the pods, replicasets and deployment created using kubectl get all.

Once you create a deployment there is a revision made for that which can be check using kubectl rollout history deployment/<deployment-name>.

Let’ change the image and do the deployment.

The replica update will done using rolling update which create a pod and remove existing to help zero downtime.

If you need to undo your deployment you can simply do that using kubectl rollout undo deployment/<deployment-name>.

As you can see the image is rollback to perl image and the first revision is removed and add a new revision for the rollback to keep track of the deployments.

Hope you got a basic understanding of k8s pods, replicasets and deployments. In the next post will talk about services and access our nginx server.

If you have found this helpful please hit that 👏 and share it on social media :)