Friday 24 July 2020

ReplicaSet: Changing the Pod template do not have any impact on currently running nodes

You can modify ReplicaSet Pod template at any time. This modification of Pod template does not reflect on the currently running pods, these changes will be reflected on new pods.

 

How can I make sure that old pods reflected with a new pod template?

Just delete them, then ReplicaSet automatically creates new Pods with the updated template.

 

Let’s confirm this with an example.

 

replicaSetLabels.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: employee-service-replica-set
  labels:
    app: employee-service-replica-set
    author: krishna
    serviceType: webservice
spec:
  template:
    metadata:
      name: employee-service
      labels:
        app: employee-service
        author: krishna
        serviceType: webservice
    spec:
      containers:
      - name: employee-service-container
        image: jboss/wildfly

  replicas: 5
  selector:
    matchLabels:
      app: employee-service

Create ReplicaSet from the above definition file.

$kubectl create -f replicaSetLabels.yml
replicaset.apps/employee-service-replica-set created

You can query Pods and their labels by executing the below command.

$kubectl get pods --show-labels
NAME                                 READY   STATUS    RESTARTS   AGE   LABELS
employee-service-replica-set-gkbhg   1/1     Running   0          31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-qhpcx   1/1     Running   0          31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xbtjb   1/1     Running   0          31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xhh2h   1/1     Running   0          31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xtnv4   1/1     Running   0          31s   app=employee-service,author=krishna,serviceType=webservice

Now, let’s edit the ReplicaSet definition and update the author from ‘krishna’ to ‘Shiney’ in the Pod template section (spec.template.matadata.labels.author).

 

You can edit the replica set by executing the below command.

kubectl edit rc {my_replica_set}

 

Example

kubectl edit rs employee-service-replica-set

 

Change the author key from ‘krishna’ to ‘Shiney’.

$kubectl edit rs employee-service-replica-set
replicaset.apps/employee-service-replica-set edited
Query the Pods again to confirm that this label change will not reflect on currently running pods.
$kubectl get pods --show-labels
NAME                                 READY   STATUS    RESTARTS   AGE     LABELS
employee-service-replica-set-gkbhg   1/1     Running   0          2m31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-qhpcx   1/1     Running   0          2m31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xbtjb   1/1     Running   0          2m31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xhh2h   1/1     Running   0          2m31s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xtnv4   1/1     Running   0          2m31s   app=employee-service,author=krishna,serviceType=webservice

Let’s delete the pod ‘employee-service-replica-set-gkbhg’.

$kubectl delete pod employee-service-replica-set-gkbhg
pod "employee-service-replica-set-gkbhg" deleted

Query the Pods again.

$kubectl get pods --show-labels
NAME                                 READY   STATUS    RESTARTS   AGE     LABELS
employee-service-replica-set-qhpcx   1/1     Running   0          3m26s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-rj6kn   1/1     Running   0          35s     app=employee-service,author=Shiney,serviceType=webservice
employee-service-replica-set-xbtjb   1/1     Running   0          3m26s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xhh2h   1/1     Running   0          3m26s   app=employee-service,author=krishna,serviceType=webservice
employee-service-replica-set-xtnv4   1/1     Running   0          3m26s   app=employee-service,author=krishna,serviceType=webservice

From the output, you can confirm that the author ‘Shiney’ reflected for newly created Pod.




Previous                                                    Next                                                    Home

No comments:

Post a Comment