How a ReplicaSet works?
ReplicaSet is a next generation of replicationcontroller both replicaset and replicationcontroller ensure that pods that are running in the kubernetes cluster is matching the desired state of pods which are required. Following was the overview of how a replicaset operates:
- Mention the desired state: You can define the no.of pods required for the application while creating the replicaset in the yaml file. The no.of replicas depends upon the incoming traffic of the application.
- Scheduling pods: After writing the yaml file know to deploy the pods using that yaml file replicaset will start scheduling pods according to the number you have mentioned.
- Maintains the Desired: Replicaset will always try to maintain the desired no.of pods which is mentioned in the yaml file if any of the pod is deleted and the replicaset will automatically create a new pod.
- Monitoring the pods: Replicaset monitors the pod continuously and always makes sure that the pod desired count of the pod is maintained in the kubernetes cluster.
Kubernetes – Creating a ReplicaSet
Pre-requisite: Kubernetes
A ReplicaSet is a key component of a Kubernetes application. It is a controller that ensures that a specified number of pod replicas are running at any given time. It is used to automatically replace any pods that fail, get deleted, or are terminated, ensuring the desired number of replicas are always available to serve requests. When a ReplicaSet is created, it creates the desired number of replicas of the specified pod. It then continuously monitors the status of the replicas to ensure that the desired number is always maintained. If the number of replicas exceeds the desired number, the ReplicaSet will delete excess replicas.
- Pods: A pod is the smallest deployable unit that can be created and managed. It is a logical host for one or more containers and all containers in a pod run on the same node in a cluster.
- Cluster: A cluster is a group of physical or virtual machines that are used to host containerized applications. It consists of a group of worker machines, called nodes, that run the containers, and a control plane that manages the nodes and the applications running on them.