|
| 1 | +# Update Deployment and Service in Kubernetes |
| 2 | + |
| 3 | +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: |
| 4 | + |
| 5 | +- 1.) Modify the service nodeport from `30008` to `32165` |
| 6 | +- 2.) Change the replicas count from `1` to `5` |
| 7 | +- 3.) Update the image from `nginx:1.17` to `nginx:latest` |
| 8 | + |
| 9 | +> Note: The kubectl utility on jump_host is configured to operate with the Kubernetes cluster. |
| 10 | +
|
| 11 | +## Steps |
| 12 | + |
| 13 | +1. Lets extract deployments into yaml file: |
| 14 | + |
| 15 | + ```sh |
| 16 | + kubectl get deployments.apps nginx-deployment -o yaml > nginx-deployment.yml |
| 17 | + ``` |
| 18 | + |
| 19 | +2. Let's update replicas and container image: |
| 20 | +
|
| 21 | + ```sh |
| 22 | + vi nginx-deployment.yml |
| 23 | + ``` |
| 24 | +
|
| 25 | + - `replicas`: 1 to 5 |
| 26 | + - `image`: nginx:1.17 to nginx:latest |
| 27 | +
|
| 28 | +3. Update deployment |
| 29 | +
|
| 30 | + ```sh |
| 31 | + kubectl apply -f nginx-deployment.yml |
| 32 | + ``` |
| 33 | +
|
| 34 | +4. Let's extract service |
| 35 | + |
| 36 | + ```sh |
| 37 | + kubectl get svc |
| 38 | + kubectl get svc nginx-service -o yaml > svc.yml |
| 39 | + ``` |
| 40 | + |
| 41 | +5. Let's change the nodeport |
| 42 | +
|
| 43 | + ```sh |
| 44 | + vi svc.yml |
| 45 | + ``` |
| 46 | +
|
| 47 | + - change `nodeport`: 30008 to 32165 |
| 48 | +
|
| 49 | + ```YAML |
| 50 | + apiVersion: v1 |
| 51 | + kind: Service |
| 52 | + metadata: |
| 53 | + annotations: |
| 54 | + kubectl.kubernetes.io/last-applied-configuration: | |
| 55 | + {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"nginx-service","namespace":"default"},"spec":{"ports":[{"nodePort":30008,"port":80,"targetPort":80}],"selector":{"app":"nginx-app"},"type":"NodePort"}} |
| 56 | + creationTimestamp: "2025-09-16T15:47:20Z" |
| 57 | + name: nginx-service |
| 58 | + namespace: default |
| 59 | + resourceVersion: "755" |
| 60 | + uid: 11a1de9f-9881-4be2-afa3-7c9e64c5c33a |
| 61 | + spec: |
| 62 | + clusterIP: 10.96.194.172 |
| 63 | + clusterIPs: |
| 64 | + - 10.96.194.172 |
| 65 | + externalTrafficPolicy: Cluster |
| 66 | + internalTrafficPolicy: Cluster |
| 67 | + ipFamilies: |
| 68 | + - IPv4 |
| 69 | + ipFamilyPolicy: SingleStack |
| 70 | + ports: |
| 71 | + - nodePort: 32165 |
| 72 | + port: 80 |
| 73 | + protocol: TCP |
| 74 | + targetPort: 80 |
| 75 | + selector: |
| 76 | + app: nginx-app |
| 77 | + sessionAffinity: None |
| 78 | + type: NodePort |
| 79 | + status: |
| 80 | + loadBalancer: {} |
| 81 | + ``` |
| 82 | +
|
| 83 | +6. Update service |
| 84 | +
|
| 85 | + ```sh |
| 86 | + kubectl apply -f svc.yml |
| 87 | + ``` |
| 88 | +
|
| 89 | +7. Verify |
| 90 | +
|
| 91 | + ```shell |
| 92 | + kubectl get svc |
| 93 | + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 94 | + kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21m |
| 95 | + nginx-service NodePort 10.96.194.172 <none> 80:32165/TCP 17m |
| 96 | + ``` |
| 97 | +
|
| 98 | + > replicas: |
| 99 | +
|
| 100 | + ```$ kubectl get pods |
| 101 | + NAME READY STATUS RESTARTS AGE |
| 102 | + nginx-deployment-854ff588b7-fq8c4 1/1 Running 0 9m25s |
| 103 | + nginx-deployment-854ff588b7-k6fhw 1/1 Running 0 9m26s |
| 104 | + nginx-deployment-854ff588b7-mm7x4 1/1 Running 0 9m39s |
| 105 | + nginx-deployment-854ff588b7-rscc2 1/1 Running 0 9m39s |
| 106 | + nginx-deployment-854ff588b7-swrwm 1/1 Running 0 9m39s |
| 107 | + ``` |
0 commit comments