Kubernetes - ReplicaSet

Kubernetes - ReplicaSet

In this article let us understand how ReplicaSet in Kubernetes work with an example.

Step 1 : Check the nodes present in the cluster

kubectl get nodes        
Article content

Step 2: Create a file rs-nginx.yml

Article content

Step 3: Create the replicas and check that 5 pods are running.

kubectl apply -f rs-nginx.yml        
Article content

Delete any pod and see the results:

  • Let us delete the pod rs-nginx-8wplz

kubectl delete pod rs-nginx-8wplz        
Article content

  • The pod gets deleted but immediately another pod will be created automatically as we have already mentioned at any given point of time 5 pods should be running.
  • rs-nginx-sbhg6 is the new one created 5 seconds ago


If we create another pod with the same label and see whether more than 5 pods will be created or not.

Article content

  • In one terminal create the pod

kubectl apply -f pod.yml        
Article content

  • In another terminal run the below command and watch the pods

kubectl get pods -w        
Article content

  • You can see that even the new pod is deleted immediately. At any given point of time only 5 pods will be kept running!

Hope this gives the clear understanding of ReplicaSet.

To view or add a comment, sign in

More articles by Kiran Kulkarni

Insights from the community

Others also viewed

Explore topics