You are currently viewing What Is ReplicaSet In Kubernetes

What Is ReplicaSet In Kubernetes

What Is ReplicaSet In Kubernetes

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed ReplicationController in Kubernetes.

In this blog post, we will discuss ReplicaSet which is the new version of ReplicationController with some added features. In real-world scenarios, we hardly deploy a pod directly. Instead, pods are deployed using the pod controller. ReplicaSet is one of the pod controllers which ensures that a specified number of pod replicas are running at any one time.

What Is ReplicaSet?

A ReplicaSet’s purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods. A ReplicaSet is defined with fields, including a selector that specifies how to identify Pods it can acquire, a number of replicas indicating how many Pods it should be maintaining, and a pod template specifying the data of new Pods it should create to meet the number of replicas criteria. A ReplicaSet then fulfills its purpose by creating and deleting Pods as needed to reach the desired number. When a ReplicaSet needs to create new Pods, it uses its Pod template.

What Is ReplicaSet In Kubernetes

A ReplicaSet is linked to its Pods via the Pods’ metadata.ownerReferences field, which specifies what resource the current object is owned by. All Pods acquired by a ReplicaSet have their owning ReplicaSet’s identifying information within their ownerReferences field. It’s through this link that the ReplicaSet knows of the state of the Pods it is maintaining and plans accordingly. A ReplicaSet identifies new Pods to acquire by using its selector. If there is a Pod that has no OwnerReference or the OwnerReference is not a Controller and it matches a ReplicaSet’s selector, it will be immediately acquired by said ReplicaSet.

ReplicationController Vs ReplicaSet:

  • Replication Controller only supports equality-based selector. for eg: environment = production
  • Replica Set supports the new set-based selector. This gives more flexibility. for eg: environment in (production, qa)
  • rolling-update command is used for updating the replication controller.
  • rollout command is used for updating the replica set.

ReplicaSet manifest file syntax:

replicasetMetadata attributes:

  • annotations: Key value map stored with a resource for arbitrary metadata.
  • clusterName: The name of the cluster which the object belongs to.
  • creationTimestamp: Timestamp representing the server time when this object was created.
  • deletionGracePeriodSeconds: Seconds allowed for gracefully terminate before forcefully removed from the system.
  • deletionTimestamp: RFC 3339 date and time at which this resource will be deleted. Is not directly settable by a client.
  • finalizers: Must be empty before the object is deleted from the registry.
  • generateName: Optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided.
  • generation: A sequence number representing a specific generation of the desired state. Populated by the system. Read-only.
  • initializers: An initializer is a controller which enforces some system invariant at object creation time.
  • labels: Map of string keys and values that can be used to organize and categorize (scope and select) objects.
  • name: Name must be unique within a namespace.
  • namespace: Namespace defines the space within each name must be unique, default namespace is default.
  • ownerReferences: List of objects depended by this object.
  • resourceVersion: An opaque value that represents the internal version of this object used to determine when objects have changed.
  • selfLink: SelfLink is a URL representing this object. Populated by the system. Read-only.
  • uid: UID is the unique in time and space value for this object

replicasetSpec attributes:

  • minReadySeconds: Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0
  • replicas: Replicas is the number of desired replicas. This is a pointer to distinguish between explicit zero and unspecified. Defaults to 1.
  • selector: Selector is a label query over pods that should match the Replicas count. If Selector is empty, it is defaulted to the labels present on the Pod template. Label keys and values that must match in order to be controlled by this replication controller, if empty defaulted to labels on Pod template.
  • template: Template is the object that describes the pod that will be created if insufficient replicas are detected.

ReplicaSet Demo:

Step 1: Create the replicaset.

Step 2: View replicaset details.

Step 3: Scale up and scale down the number of replicas.

Step 4: Delete a pod managed by replicaset.

Step 5: Make a connection to the pod managed by replicaset.

Step 6: Cleanup.

Hope you enjoyed this article. In real world sceanrios we hardly deploy a pod directly. Instead, pods are deployed using pod controller. In the next blog post, we will discuss one of the pod controller deployment.

To get more details on Kubernetes you can follow the below link.

To get more details on Docker you can follow the below links.