DEV Community

Cover image for 12.Update Deployment and Service in Kubernetes
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

12.Update Deployment and Service in Kubernetes

Lab Information

An application deployed on the Kubernetes cluster requires an update with new features developed by the Nautilus 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

Note: The kubectl utility on jump_host is configured to operate with the Kubernetes cluster.

Lab Solutions

Step 1: Check the current state

First, let's examine the current deployment and service:

kubectl get deployment nginx-deployment
kubectl describe deployment nginx-deployment
kubectl get service nginx-service
kubectl describe service nginx-service
Enter fullscreen mode Exit fullscreen mode

Step 2: Update the service NodePort

Let's modify the service to change the NodePort from 30008 to 32165:

kubectl edit service nginx-service
Enter fullscreen mode Exit fullscreen mode

Then find the nodePort field and change 30008 to 32165, save and exit.

Step 3: Update the deployment replicas

Change the number of replicas from 1 to 5:

kubectl scale deployment nginx-deployment --replicas=5
Enter fullscreen mode Exit fullscreen mode

Step 4: Update the container image

Update the image from nginx:1.18 to nginx:latest:

kubectl set image deployment nginx-deployment nginx-container=nginx:latest
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify all changes

Let's verify each change was applied successfully:
Check service update:

kubectl get service nginx-service -o yaml | grep nodePort
Enter fullscreen mode Exit fullscreen mode

Expected output: Should show nodePort: 32165

Check replicas count:

kubectl get deployment nginx-deployment -o wide
Enter fullscreen mode Exit fullscreen mode

Expected output: Should show READY: 5/5

Check pods and their images:

kubectl get pods
kubectl describe deployment nginx-deployment | grep -A 5 "Image"
Enter fullscreen mode Exit fullscreen mode

Expected output: Should show nginx:latest


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)