Define kubernetes ReplicaSets with Example and commands

Replicaset:

A ReplicaSet is one of the Kubernetes controllers that makes sure we have a specified number of pod replicas running. 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.

 You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.

Example:

  1. creating replicaset:
[centos@ip-172-31-22-14 harshit]$ kubectl create deployment harshit --image=scmgalaxy/nginx-devopsschoolv1 --replicas=3 -n=harshit
deployment.apps/harshit created
[centos@ip-172-31-22-14 harshit]$ kubectl get deployment -n=harshit
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
harshit   3/3     3            3           15s
[centos@ip-172-31-22-14 harshit]$ kubectl get pod -n=harshit
NAME                       READY   STATUS    RESTARTS   AGE
harshit                    1/1     Running   0          109m
harshit-5gk8t              1/1     Running   0          8m58s
harshit-7c675b8d4f-dlv8l   1/1     Running   0          34s
harshit-7c675b8d4f-p9gmv   1/1     Running   0          34s
harshit-7c675b8d4f-xf7r7   1/1     Running   0          34s
harshit-xtftw              1/1     Running   0          8m58s

2.scaling replicaset:

[centos@ip-172-31-22-14 harshit]$ kubectl scale --replicas=1 deploy/harshit -n=harshit
deployment.apps/harshit scaled
[centos@ip-172-31-22-14 harshit]$ kubectl get deploy -n=harshit
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
harshit   1/1     1            1           12m