Tuesday, 7 October 2025

Update Kubernetes Deployment and Service Without Deletion in Prod (nginx-deployment)

Our course you can check :-   Udemy course 

Ques:- 

An application deployed on the Kubernetes cluster requires an update with new features developed by the application development team. The existing setup includes a deployment named nginx-deployment and a service named nginx-service. Below are the necessary changes to be implemented without deleting the deployment and service:

1.) Modify the service nodeport from 30008 to 32165

2.) Change the replicas count from 1 to 5

3.) Update the image from nginx:1.18 to nginx:latest


Ans:-

raj@jumphost ~$ kubectl get svc

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

kubernetes      ClusterIP   10.96.0.1      <none>        443/TCP        8m54s

nginx-service   NodePort    10.96.188.16   <none>        80:30008/TCP   6m40s


raj@jumphost ~$ kubectl get deploy

NAME               READY   UP-TO-DATE   AVAILABLE   AGE

nginx-deployment   1/1     1            1           6m54s


raj@jumphost ~$ kubectl get pod

NAME                                READY   STATUS    RESTARTS   AGE

nginx-deployment-58cf54c7f6-sq9d8   1/1     Running   0          7m3s


raj@jumphost ~$ kubectl patch service nginx-service -p '{"spec": {"ports": [{"port": 80, "targetPort": 80, "protocol": "TCP", "nodePort": 32165}]}}'

service/nginx-service patched


raj@jumphost ~$ kubectl get svcNAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE

kubernetes      ClusterIP   10.96.0.1      <none>        443/TCP        10m

nginx-service   NodePort    10.96.188.16   <none>        80:32165/TCP   8m26s


raj@jumphost ~$ kubectl scale deployment nginx-deployment --replicas=5

deployment.apps/nginx-deployment scaled


raj@jumphost ~$ kubectl get deployNAME               READY   UP-TO-DATE   AVAILABLE   AGE

nginx-deployment   5/5     5            5           9m14s


raj@jumphost ~$ kubectl get podNAME                                READY   STATUS    RESTARTS   AGE

nginx-deployment-58cf54c7f6-8jtw2   1/1     Running   0          23s

nginx-deployment-58cf54c7f6-dhbwl   1/1     Running   0          23s

nginx-deployment-58cf54c7f6-ph4d9   1/1     Running   0          23s

nginx-deployment-58cf54c7f6-sq9d8   1/1     Running   0          9m29s

nginx-deployment-58cf54c7f6-vjmr2   1/1     Running   0          23s


raj@jumphost ~$ kubectl get deployment nginx-deployment -o yaml | grep -i image:

      - image: nginx:1.18


raj@jumphost ~$ kubectl set image deployment/nginx-deployment nginx-container=nginx:latest

deployment.apps/nginx-deployment image updated


raj@jumphost ~$ kubectl get deployment nginx-deployment -o yaml | grep -i image:

      - image: nginx:latest


raj@jumphost ~$ kubectl get svc

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

kubernetes      ClusterIP   10.96.0.1      <none>        443/TCP        14m

nginx-service   NodePort    10.96.188.16   <none>        80:32165/TCP   11m


raj@jumphost ~$ kubectl get deploy

NAME               READY   UP-TO-DATE   AVAILABLE   AGE

nginx-deployment   5/5     5            5           12m


raj@jumphost ~$ kubectl get pod

NAME                                READY   STATUS    RESTARTS   AGE

nginx-deployment-854ff588b7-dzhpp   1/1     Running   0          46s

nginx-deployment-854ff588b7-fkvrk   1/1     Running   0          56s

nginx-deployment-854ff588b7-qknjc   1/1     Running   0          56s

nginx-deployment-854ff588b7-sjlck   1/1     Running   0          45s

nginx-deployment-854ff588b7-t2hgr   1/1     Running   0          56s

raj@jumphost ~$ 

No comments:

Post a Comment