Define kubernetes ReplicaSets with Example and commands:
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
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.
- While creating the deployment
kubectl create deployment pradeepa--image=scmgalaxy/nginx-devopsschoolv1 --replicas=3 -n=pradeepa
2. While the deployment is running
kubectl edit deploy pradeepa-n=pradeepa 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/pradeepa-n=pradeepa
Always the required number of pods are running is guaranteed.
[centos@ip-172-31-22-14 pradeepa]$ kubectl create deployment pradeepa--image=scmgalaxy/nginx-devopsschoolv1 --replicas=3 -n=pradeepa deployment.apps/pradeepa created [centos@ip-172-31-22-14 pradeepa]$ kubectl get deploy -n=pradeepa NAME READY UP-TO-DATE AVAILABLE AGE pradeepa 3/3 3 3 9s [centos@ip-172-31-22-14 pradeepa]$ kubectl get pods -n=pradeepa NAME READY STATUS RESTARTS AGE pradeepa-88bcb4f5d-9jq4d 1/1 Running 0 18s pradeepa-88bcb4f5d-dtn2c 1/1 Running 0 18s pradeepa-88bcb4f5d-hppkz 1/1 Running 0 18s [centos@ip-172-31-22-14 pradeepa]$ kubcectl delete pod pradeepa-88bcb4f5d-hppkz -n=pradeepa -bash: kubcectl: command not found [centos@ip-172-31-22-14 pradeepa]$ kubectl delete pod pradeepa-88bcb4f5d-hppkz -n=pradeepa pod "pradeepa-88bcb4f5d-hppkz" deleted [centos@ip-172-31-22-14 pradeepa]$ kubectl get pods NAME READY STATUS RESTARTS AGE pradeepa1/1 Running 0 93m [centos@ip-172-31-22-14 pradeepa]$ kubectl get pods -n=pradeepa NAME READY STATUS RESTARTS AGE pradeepa-88bcb4f5d-9jq4d 1/1 Running 0 52s pradeepa-88bcb4f5d-dtn2c 1/1 Running 0 52s pradeepa-88bcb4f5d-qms2q 1/1 Running 0 10s //this is the newly created pod after deleting the existing POD