When iterating on applications deployed as pods on a Virtual Node, you may need to update a container image to fix bugs or add new features. To avoid service disruptions, you often need to retain the pod's IP address during the update. This guide shows how to use kubectl commands to update the container image of an Elastic Container Instance (ECI) pod without changing its IP address.
Prerequisites
You have prepared and pushed the new container image to an image repository.
Procedure
This example updates the container image of an Nginx Pod from nginx:1.7.9 to nginx:1.9.6 while retaining the pod's IP address.
To run this example, ensure that the Virtual Private Cloud (VPC) for your cluster has an Internet NAT gateway and SNAT rules configured. This way, the image can be pulled over the Internet.
Create an ECI pod.
kubectl create -f nginx.yamlThe following
nginx.yamlfile uses thenginx:1.7.9container image.apiVersion: v1 kind: Pod metadata: name: nginx namespace: default labels: alibabacloud.com/eci: "true" spec: containers: - image: nginx:1.7.9 imagePullPolicy: Always name: nginxQuery the pod information.
Check the IP address of the pod.
kubectl get pod/nginx -n default -o wideThe output shows the pod's IP address is 172.16.22.193.
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx 1/1 Running 0 5m5s 172.16.22.193 virtual-kubelet-cn-beijing-e <none> <none>Check the pod's image tag.
kubectl get pod/nginx -n default -o=custom-columns='IMAGE:spec.containers[*].image'The output shows the Pod's container image is
nginx:1.7.9.IMAGE nginx:1.7.9
Choose one of the following methods to update the image:
kubectl patch
Run the
kubectl patchcommand to directly update the container image tag.kubectl patch pod nginx -p '{"spec":{"containers":[{"name": "nginx","image": "nginx:1.9.6"}]}}'kubectl edit
Run the
kubectl editcommand to edit the Pod manifest and update the container image tag.kubectl edit pod/nginx -o yamlkubectl apply
Open the
nginx.yamlconfiguration file, update the container image tag, and then run thekubectl applycommand to apply the change.kubectl apply -f nginx.yaml
Verify the updated pod information.
Check the pod's IP address.
kubectl get pod/nginx -n default -o wideThe output confirms the pod's IP address,
172.16.22.193, is unchanged.NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx 1/1 Running 1 19m 172.16.22.193 virtual-kubelet-cn-beijing-e <none> <none>Check the pod's image tag.
kubectl get pod/nginx -n default -o=custom-columns='IMAGE:spec.containers[*].image'The output shows the container image is now
nginx:1.9.6.IMAGE nginx:1.9.6