🚀 DevOps Certified Professional
📅 Starting: 1st of Every Month 🤝 +91 8409492687 | 🤝 +1 (469) 756-6329 🔍 Contact@DevOpsSchool.com

Define kubernetes ReplicaSets with Example and commands?

DevOps

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

ReplicaSet:

A ReplicaSet’s purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods.

There are many ways we can use replicasets such that always required number of pods running is guarangteed.

  1. While creating the deployment
 kubectl create deployment ramesh --image=scmgalaxy/nginx-devopsschoolv1 --replicas=3 -n=ramesh

2. While the deployment is running

kubectl edit deploy ramesh -n=ramesh
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable //change this value to desired number of replicas

3. Using scale option

kubectl scale --replicas=1 deploy/ramesh -n=ramesh

Always the required number of pods are running is guaranteed.

[centos@ip-172-31-22-14 ramesh]$ kubectl create deployment ramesh --image=scmgalaxy/nginx-devopsschoolv1 --replicas=3 -n=ramesh
deployment.apps/ramesh created
[centos@ip-172-31-22-14 ramesh]$ kubectl get deploy -n=ramesh
NAME READY UP-TO-DATE AVAILABLE AGE
ramesh 3/3 3 3 9s
[centos@ip-172-31-22-14 ramesh]$ kubectl get pods -n=ramesh
NAME READY STATUS RESTARTS AGE
ramesh-88bcb4f5d-9jq4d 1/1 Running 0 18s
ramesh-88bcb4f5d-dtn2c 1/1 Running 0 18s
ramesh-88bcb4f5d-hppkz 1/1 Running 0 18s
[centos@ip-172-31-22-14 ramesh]$ kubcectl delete pod ramesh-88bcb4f5d-hppkz -n=ramesh
-bash: kubcectl: command not found
[centos@ip-172-31-22-14 ramesh]$ kubectl delete pod ramesh-88bcb4f5d-hppkz -n=ramesh
pod "ramesh-88bcb4f5d-hppkz" deleted
[centos@ip-172-31-22-14 ramesh]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nagesh 1/1 Running 0 93m
[centos@ip-172-31-22-14 ramesh]$ kubectl get pods -n=ramesh
NAME READY STATUS RESTARTS AGE
ramesh-88bcb4f5d-9jq4d 1/1 Running 0 52s
ramesh-88bcb4f5d-dtn2c 1/1 Running 0 52s
ramesh-88bcb4f5d-qms2q 1/1 Running 0 10s //this is the newly created pod after deleting the existing POD