Getting Started with Kubernetes — Chapter # 02
Replicaset

Getting Started with Kubernetes — Chapter # 02

ReplicaSet:

In K8s, whenever we are talking about the multiple copies of any resource like pods, we are actually referring to replicaset. ReplicaSet is the resource that helps creating and managing multiple copies of application in K8s. The replicaset notices the missing pod and creates a replacement pod.

Article content
Replicaset

ReplicaSet has three essential parts:

Label selector => determines what Pods are in the ReplicaSet scope.

Replica count => specifies the desired number of Pods that should be running.

Pod template=> ReplicaSet uses to create Pod.

How to create a replicaset?

Article content
Replicaset Creation

Some Useful Commands:

To create the ReplicaSet:

kubectl create -f <file-name>.yaml        

Example:

kubectl create -f replicaset.yaml        

To check ReplicaSet:

kubectl get replicasets        

To get Pods information:

kubectl get pods        

How to delete a ReplicaSet and Pods?

Some Useful Commands:

To delete Pod:

kubectl delete pod <pod-name>        

If you delete the pod and then run again the command of (kubectl get pods), it will again create the new pods to fulfill the desired output.

To delete the ReplicaSet:

Once the pods are deleted, run the following command to delete replicaset:

kubectl delete replicaset <replicaset-name>        

If to delete replicaset but not pods:

Here, 'kubectl delete' command with the '--cascade=false' flag. This flag ensures that only the ReplicaSet itself is deleted, leaving the pods it manages intact.

kubectl delete replicaset <replicaset-name> --cascade=false        

To scale the number of replicas in a ReplicaSet to 5:

kubectl scale replicaset <replicaset-name> --replicas=5        

Thank you for reading Chapter 2 of Kubernetes series. Stay tuned for Chapter 3.

To view or add a comment, sign in

More articles by Syed Zain Rashid

Insights from the community

Others also viewed

Explore topics