Kubernetes Replicaset

MrDevSecOps
3 min readFeb 15, 2022

ReplicaSet is a process that runs multiple instances of a Pod and keeps the specified number of Pods constant.

  • let’s take an example where we have a set of two worker nodes in a cluster as in the above diagram.
  • we have the front end, running on worker1 and the backend is on the worker2 node.
  • The application is working great as long as the pods and nodes are healthy and running.
  • Please note, these two pods are running without any controllers backing these parts as of now.
  • So the problem comes here, we know the frontend pod fails or dies for some reason and users accessing this Web app will no longer have access to it anymore.
  • The pod is not coming back online even after 15 or 20 minutes and to solve the problem developer needs to redeploy it manually.
  • It is OK if it is like 10 or 15 pots are running on the cluster and they’re not that critical.
  • But in a prod environment, there will be thousands of pods running in real-time and they’re critical.
  • It is almost impossible to recreate them manually if the pod dies for any reason.
  • That problem is solved by a replica set.

What is the replica set?

  • A ReplicaSet is a process that runs multiple instances of a Pod and keeps the specified number of Pods constant.
  • Its purpose is to maintain the specified number of Pod instances running in a cluster at any given time to prevent users from losing access to their application when a Pod fails or is inaccessible.
  • So taking the same example that if the frontend pod is created by replica set, the new front pod will be recreated.
  • Replica set also provides high availability and load balancing of the application.
  • It continuously monitors that application and recreates that if the pod dies.

Replication Controller Vs ReplicaSet

  • Replication controllers are older, it is replaced with the newer version, and that is called this replica Set.
  • The replication controller is not used anymore.
  • The concept that we discussed so far applies to both the replication controller and the replica set.
  • The difference between the replica set and the application controller is very minimal.
  • In real-time, we generally do not create or manage a replica set or even pods manually.
  • We deploy pods in Kubernetes using a resource type called deployment.
  • That deployment creates a replica set in the background automatically for us then this replica is responsible for creating and managing the desired number of pod and pod replicas mentioned in the deployment file.

We will discuss deployment in another article.

--

--

MrDevSecOps

Integrating security into the software development lifecycle.