Update an Existing Deployment in Kubernetes

Ticker

6/recent/ticker-posts

Update an Existing Deployment in Kubernetes

Question : There is an application deployed on Kubernetes cluster. Recently the Nautilus application development team developed a new version of the application that needs to be deployed now. As per new updates some new changes need to be made in this existing setup. So update the deployment and service as per details mentioned below:

We already have a deployment named nginx-deployment and service named nginx-service. Some changes need to be made in this deployment and service, make sure not to delete the deployment and service.

1.) Change the service nodeport from 30008 to 32165

2.) Change replicas count from 1 to 5

3.) Add a command: ["sh","-c","while true; do apt update; apt install -y vim php ; sleep 3; done"]

4.) Change the image from nginx:1.19 to nginx:latest



Please Note :-  Perform the below commands based on your question  server,  user name & other details might differ . So please read task carefully before executing. All the Best 👍

Solution:  

1. At first  run below commands to check  the existing setup    

thor@jump_host /$ kubectl get deploy

NAME               READY   UP-TO-DATE   AVAILABLE   AGE

nginx-deployment   1/1     1            1           14s

thor@jump_host /$

thor@jump_host /$ kubectl get service

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE

kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP        86m

nginx-service   NodePort    10.96.131.156   <none>        80:30008/TCP   2m20s

thor@jump_host /$

thor@jump_host /$ kubectl get pods

NAME                                READY   STATUS    RESTARTS   AGE

nginx-deployment-57bf6d6978-wrmf4   1/1     Running   0          2m33s

thor@jump_host /$


2. Edit the services as per the task and change the port no ( refer below video)
     

thor@jump_host /$ kubectl edit service nginx-service

service/nginx-service edited

thor@jump_host /$

thor@jump_host /$ kubectl get service

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE

kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP        89m

nginx-service   NodePort    10.96.131.156   <none>        80:32165/TCP   5m

thor@jump_host /$


3. Edit the deployment and do the changes as per the task  ( refer below video)
    

thor@jump_host /$ kubectl edit deploy nginx-deployment

deployment.apps/nginx-deployment edited

thor@jump_host /$

thor@jump_host /$ kubectl get deploy

NAME               READY   UP-TO-DATE   AVAILABLE   AGE

nginx-deployment   4/5     4            4           13m

thor@jump_host /$

thor@jump_host /$ kubectl get pods

NAME                                READY   STATUS        RESTARTS   AGE

nginx-deployment-57bf6d6978-42rfc   0/1     Terminating   0          13s

nginx-deployment-57bf6d6978-dhwzm   0/1     Terminating   0          13s

nginx-deployment-57bf6d6978-wrmf4   0/1     Terminating   0          13m

nginx-deployment-6fc57985b9-bjwxj   1/1     Running       0          13s

nginx-deployment-6fc57985b9-lx7cb   1/1     Running       0          13s

nginx-deployment-6fc57985b9-qvnbj   1/1     Running       0          13s

nginx-deployment-6fc57985b9-s4524   1/1     Running       0          6s

nginx-deployment-6fc57985b9-vpdnw   1/1     Running       0          7s

thor@jump_host /$

    
4.  Wait for  deployment & pods to get ready & running status
    

thor@jump_host /$ kubectl get deploy

NAME               READY   UP-TO-DATE   AVAILABLE   AGE

nginx-deployment   5/5     5            5           14m

thor@jump_host /$ kubectl get pods

NAME                                READY   STATUS    RESTARTS   AGE

nginx-deployment-6fc57985b9-bjwxj   1/1     Running   0          118s

nginx-deployment-6fc57985b9-lx7cb   1/1     Running   0          118s

nginx-deployment-6fc57985b9-qvnbj   1/1     Running   0          118s

nginx-deployment-6fc57985b9-s4524   1/1     Running   0          111s

nginx-deployment-6fc57985b9-vpdnw   1/1     Running   0          112s

thor@jump_host /$


5.  Click on Finish & Confirm to complete the task successful

Happy Learning!!!!

Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge 





Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user