ReplicaSet Scaling & Its Behaviour

Kubernetes gives you two ways to run multiple identical Pods: ReplicaSets and Deployments.

A ReplicaSet keeps a fixed number of Pods running. A Deployment adds intelligence on top with rolling updates, rollbacks, and version history. The only difference we need to do in its yaml is change the kind.

The difference between a replicaset and deployment is here but 99 % of time we will use deployment only.

FeatureDeployment (Smart Controller)ReplicaSet (Pod Counter)
Rolling updates Yes No
Rollbacks Yes No
Version history Yes No
Behaviour on template changeCreates a new ReplicaSetKills all pods and recreates
DowntimeZero downtimePossible downtime
PurposeFull lifecycle managementMaintain N identical pods

1. Creating the Namespace

kubectl create namespace replica
kubectl config set-context --current --namespace=replica

2. Applying the ReplicaSet

The only change in replicaset vs deployment is we change the kind from deployment to replicaset 

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-rep
  labels:
    app: my-rep
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-rep
  template:
    metadata:
      labels:
        app: my-rep
    spec:
      containers:
      - name: httpd
        image: httpd

3. Verifying the ReplicaSet

kubectl get rs
kubectl describe rs my-rep
kubectl get pods -o wide

4. Scaling the ReplicaSet by Imperative means 

ie : testing 

kubectl scale replicaset my-rep --replicas=5

5. Self-Healing Demo

kubectl delete pod <pod-name>
kubectl get pods -o wide

6. Declarative 

We will just edit the yaml file and add replicas =3 as usual by editing the deploy file and then YAML becomes the source of truth

kubectl apply -f deploy.yml

7. Update the deployment

We will just edit the yaml file and add a new image as nginx:19.1

kubectl set image deployment/app nginx=nginx:19.1

8. Status of the deployment

kubectl roll out status deployment/app

9. History of the deployment

kubectl roll out history deployment/app

10. Und the deployment

kubectl roll undo deployment/app

(Visited 1 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.