Kubernetes 101 : An Overview of ReplicaSet and their role.



ReplicaSets:

A replicaSet is a simple kubernetes controller for managing the pods.
Using a replicaSetwe can tell kubernetes to have, and keep a specific number of pods running.

The below replicaSet example instructs kubernetes to keep three replicas of "debian" pods running at all times.


ReplicaSet and Selectors:

Replicasets use different selectors, for example the "matchLabels" in the above Yaml file.
We could also use other variables like "matchExpressions" as a selector.

The replicaSet makes sure its "replicas" number matches the number of the running pods that have a label that matches its selector "debian-app".

When a pod with the label "debian-app" crashes or exits, the replicaSet deploys a replacement pod for it.

We create our replicaSet using the below command:


To check if our pods have been successfully deployed, we use the below command:



Deleting a pod:


If we delete one of the 
above pods, the replicaSet will create a replacement pod for it:


We can then check, if the replicaSet created a replacement for our deleted pod using the below command:


As we can see, the replicaSet deployed a new pod with a new name
"replica-debian-198340978-fd89s", so that the number of the running pods always matches the "replicas" value.

Adopting pods:

If we already have a pod running with the label "debian-app", the replicaSet we created above, will only create two pods instead of three, and it will "adopt" the third pod with the label "debian-app", that is already running.


Comments

Leave as a comment:

Archive