samshers
samshers

Reputation: 3680

In Kubernetes, what is the real purpose of replicasets?

I am aware about the hierarchical order of k8s resources. In brief,

  1. service: a service is what exposes the application to outer world (or with in cluster). (The service types like, CluserIp, NodePort, Ingress are not so much relevant to this question. )
  2. deployment: a deployment is what is responsible to keep a set of pods running.
  3. replicaset: a replica set is what a deployment in turn relies on to keep the set of pods running.
  4. pod: - a pod consist of a container or a group of container
  5. container - the actual required application is run inside the container.

The thing i want to empasise in this question is, why we have replicaset. Why don't the deployment directly handle or take responsibility of keeping the required number of pods running. But deployment in turn relies on replicset for this.

If k8s is designed this way there should be definitely some benefit of having replicaset. And this is what i want to explore/understand in depth.

Upvotes: 6

Views: 1166

Answers (1)

RyanDotnet
RyanDotnet

Reputation: 144

Both essentially serves the same purpose. Deployments are a higher abstraction and as the name suggests it deals with creating, maintining and upgrading the deployment (collection of pods) as a whole. Whereas, ReplicationControllers or Replica sets primary responsibility is to maintain a set of identical replicas (which you can achieve declaratively using deployments too, but internally it creates a resplicaset to enable this).

More specifically, when you are trying to perform a "rolling" update to your deployment, such as updating the image versions, the deployment internally creates a new replica set and performs the rollout. during the rollout you can see two replicasets for the same deployment. So in other words, Deployment needs the lower level "encapsulation" of Replica sets to achive this. enter image description here

Upvotes: 6

Related Questions