Shashikant shah

Sunday, 25 February 2024

What is a ReplicaSet in Kubernetes.

 1. What are Kubernetes replicaSets?

A ReplicaSet purpose is to maintain a stable set of replica Pods running at any given time.

Pod Replication: A ReplicaSet maintains a stable set of replica pods running at the same time. If there are too few replicas, it creates additional pods to match the desired number, and if there are too many, it removes excess pods.

Declarative Specification: You define the desired state of your ReplicaSet in a declarative way using a Kubernetes manifest file, specifying attributes such as the number of replicas, the template for creating pods, and any selectors to match pods.

Selector-Based Matching: ReplicaSets use label selectors to identify the pods they manage. They ensure that the number of pods matching the specified label selector is maintained.

Self-Healing: ReplicaSets continuously monitor the state of pods they manage. If a pod fails or is deleted, the ReplicaSet automatically creates a replacement pod to maintain the desired number of replicas.

Scalability and Rolling Updates: ReplicaSets support horizontal scaling by allowing you to easily increase or decrease the number of replicas. They also facilitate rolling updates by enabling you to update pod templates in a controlled manner, ensuring zero downtime during updates.

















ReplicaSet work with selector and labels .



replicaSet yaml file details :-














# cat replicaSet/first.yaml

apiVersion: apps/v1

kind: ReplicaSet

metadata:

  name: test-replicaset

spec:

  replicas: 3

  selector:

    matchLabels:

      tier: frontend

  template:

    metadata:

      labels:

        tier: frontend

    spec:

      containers:

      - name: nginx-container

        image: nginx


# kubectl apply -f first.yaml

# kubectl get rs -o wide






Desired State:- The state of pods which is desired.

Current State:- The actual state of pods which are running.

READY:- The number of replicas that are ready (i.e., in a ready state).

AGE:- The age of the ReplicaSet, indicating how long it has been running.

CONTAINERS:- The name(s) of the container(s) running within the ReplicaSet.

IMAGES:- The image(s) used by the container(s).

SELECTOR:- The label selector used to match pods controlled by this ReplicaSet.

 

Pods labels:-

# kubectl get pods --show-labels









# kubectl describe rs test-replicaset














For delete replicaSet:-

# kubectl  delete  rc  test-replicaset

For Scale a ReplicaSet:

# kubectl scale --replicas=<number-of-replicas> rs <replicaset-name>

For Edit a ReplicaSet:

# kubectl edit rs <replicaset-name>

For Rollout History of a ReplicaSet:

# kubectl rollout undo rs <replicaset-name>

Pause and Resume a ReplicaSet:

# kubectl rollout pause rs <replicaset-name>

# kubectl rollout resume rs <replicaset-name>















No comments:

Post a Comment