100-Days-Of-DevOps-Challenge-KodeKloud

Execute Rolling Updates in Kubernetes

An application currently running on the Kubernetes cluster employs the nginx web server. The Nautilus application development team has introduced some recent changes that need deployment. They’ve crafted an image nginx:1.18 with the latest updates.

Note: The kubectl utility on jump_host is set up to operate with the Kubernetes cluster

Steps

  1. Let’s get the deployments, and pods

     kubectl get deployments.apps
     NAME               READY   UP-TO-DATE   AVAILABLE   AGE
     nginx-deployment   3/3     3            3           4m33s
    
     kubectl get pods
     NAME                               READY   STATUS    RESTARTS   AGE
     nginx-deployment-989f57c54-mnznk   1/1     Running   0          4m52s
     nginx-deployment-989f57c54-sqf5h   1/1     Running   0          4m52s
     nginx-deployment-989f57c54-vgjd8   1/1     Running   0          4m52s
    
  2. Let’s find details of the deployments for any pod

     kubectl describe pods nginx-deployment-989f57c54-mnznk
    
     Name:             nginx-deployment-989f57c54-mnznk
     Namespace:        default
     Priority:         0
     Service Account:  default
     Node:             kodekloud-control-plane/172.17.0.2
     Start Time:       Mon, 15 Sep 2025 10:38:31 +0000
     Labels:           app=nginx-app
                     pod-template-hash=989f57c54
     Annotations:      <none>
     Status:           Running
     IP:               10.244.0.6
     IPs:
     IP:           10.244.0.6
     Controlled By:  ReplicaSet/nginx-deployment-989f57c54
     Containers:
     nginx-container:
         Container ID:   containerd://5928ff11805390e2ac2b10bbaee9a5dcb540d6c534d162ca49c975c270280d11
         Image:          nginx:1.16
         Image ID:       docker.io/library/nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
         Port:           <none>
         Host Port:      <none>
         State:          Running
         Started:      Mon, 15 Sep 2025 10:38:38 +0000
         Ready:          True
         Restart Count:  0
         Environment:    <none>
         Mounts:
         /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-v2jf9 (ro)
     Conditions:
     Type              Status
     Initialized       True 
     Ready             True 
     ContainersReady   True 
     PodScheduled      True 
     Volumes:
     kube-api-access-v2jf9:
         Type:                    Projected (a volume that contains injected data from multiple sources)
         TokenExpirationSeconds:  3607
         ConfigMapName:           kube-root-ca.crt
         ConfigMapOptional:       <nil>
         DownwardAPI:             true
     QoS Class:                   BestEffort
     Node-Selectors:              <none>
     Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
     Events:
     Type    Reason     Age    From               Message
     ----    ------     ----   ----               -------
     Normal  Scheduled  10m    default-scheduler  Successfully assigned default/nginx-deployment-989f57c54-mnznk to kodekloud-control-plane
     Normal  Pulling    10m    kubelet            Pulling image "nginx:1.16"
     Normal  Pulled     9m57s  kubelet            Successfully pulled image "nginx:1.16" in 5.385304195s (5.385392439s including waiting)
     Normal  Created    9m57s  kubelet            Created container nginx-container
     Normal  Started    9m57s  kubelet            Started container nginx-container
    

    We can see the current image version: 1.16

  3. Let’s update image version:

     kubectl set image deployments/nginx-deployment nginx-container=nginx:1.18
    

    We have to use set image command with deployment name and container name

  4. Let’s verify the rollout status

     kubectl rollout status deployments/nginx-deployment
    

Good to Know?

Rolling Updates

Update Strategies

Rollout Commands

Best Practices