Kubernetes Replicasets – All you need to know!

Filed Under: Random
Kubernetes Replicasets

Hello, readers! In this article, we will be focusing on Kubernetes Replicasets in detail. So, let us begin!! 馃檪

Feature of Kubernetes Replicasets

Prior to getting into the concepts of Kubernetes Replicasets, let us understand the need of the same.

Imagine, you want to scale your application to have a more live presence, we would always want a mechanism through which the application stays up. In such scenarios, we would simply want more pods to be live to keep the application running within the containers.

But, as we all know, pods are ephemeral in nature. For the same, if the Node goes down, the pods may be destroyed. In such scenario, we would completely lose access to the running applications.

This is when Replicasets come into the picture.

ReplicaSets is a kubernetes resource that maintains the availability of the pods that are specified by maintaining a stable set of the typical replica Pods at a given point of time.

For the same, Replicasets utilize the specification that is the number of pods needed to be replicated and created when found destroyed. In this case, it requires us to provide a YAML schema to the replicaset that includes the pod’s schema of creation.

So, whenever the pods get deleted, the replicaset utilizes this schema to regenerate the pods as an when needed. In case of scaling the applications in terms of pods, similar approach can be followed.

So, how would the Replicaset identify which pods to look for? Which pods count and health needs to be monitored?

This is taken care by the selector label in the Replicaset yaml schema. The selector label matches the label defined with the label provided in the Pod yaml schema.

Having understood the use of Replicasets, let us now focus on the YAML schema.

Replicaset YAML schema

Have a look at the below YAML file–

apiVersion: apps/v1
kind: ReplicaSet
  name: backend
    app: demo-app
    tier: backend
  replicas: 2
      tier: backend
        tier: backend
      - name: demo
        image: gcr.io/images/hello-world:1.0

  • The Replicaset as mentioned above helps us have copies of the pods that would spin up as soon as the desired state or count is lost.
  • For the same, the YAML schema would include the template of a Pod i.e. the entire Pod schema.
  • With the pod schema, the Replicaset can spin up pods directly to get back to the desired state.
  • The replicas label fixes a count of the number of Replicasets per deployment.

Further, we can push the build of Replicaset using the below kubernetes apply command-

kubectl apply -f replica.yaml -f -n demoapp

Let us now have a look at the created Replicaset using the below command–

kubectl get rs -n demoapp


As seen below, the Replicaset backend gets created with 2 as the desired value, having 2 as the current count and also the readiness of those two replicas.

backend    2         2         2       45s


By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.

Try working with the schema of Replicaset and do let us know your deployment experience in the comment section.

For more such posts related to Docker and Kubernetes, Stay tuned with us.

Till then, Happy Learning!! 馃檪

Generic selectors
Exact matches only
Search in title
Search in content