All Products
Search
Document Center

Elastic Container Instance:Update the container image of an ECI pod while retaining its IP address

Last Updated:Jun 16, 2026

You can update the container image of a running ECI pod using kubectl while keeping the pod's IP address unchanged, ensuring business continuity during bug fixes or feature rollouts.

How it works

ECI restarts the container in place on the same underlying host when you update the pod spec. Because the pod is not deleted and recreated, it retains the IP address assigned at creation time.

IP address retention depends on the pod running on the same host after the update. In rare cases — such as host-level infrastructure events — the pod may be rescheduled to a different host and receive a new IP address. To reduce dependency on a fixed IP address, consider accessing your pod through a Kubernetes Service instead.

Prerequisites

Make sure that you have completed the following preparations:

  • The new container image is prepared and uploaded to an image repository.

  • An Internet NAT gateway is created for the Virtual Private Cloud (VPC) of the cluster, with Source Network Address Translation (SNAT) configured to allow image pulls from the internet.

Update the container image

This example updates the NGINX container image from nginx:1.7.9 to nginx:1.9.6 while keeping the pod IP address unchanged.

Step 1: Create the pod

Create the pod using a YAML manifest.

kubectl create -f nginx.yaml

The following nginx.yaml example uses the alibabacloud.com/eci: "true" annotation to schedule the pod on Elastic Container Instance (ECI).

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: default
  alibabacloud.com/eci: "true"
spec:
  containers:
  - image: nginx:1.7.9
    imagePullPolicy: Always
    name: nginx

Step 2: Verify the initial state

  1. Check the pod's IP address.

    kubectl get pod/nginx -n default -o wide

    The output shows the pod IP address in the IP column.

    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>
  2. Check the current image tag.

    kubectl get pod/nginx -n default -o=custom-columns='IMAGE:spec.containers[*].image'

    Expected output:

    IMAGE
    nginx:1.7.9

Step 3: Update the container image

Use one of the following methods to update the image tag.

  • kubectl patch — modifies the pod spec directly with a JSON patch:

    kubectl patch pod nginx -p '{"spec":{"containers":[{"name": "nginx","image": "nginx:1.9.6"}]}}'

    The -p flag takes a JSON string that specifies the fields to update. In this example, the container named nginx has its image set to nginx:1.9.6.

  • kubectl edit — opens the pod spec in an interactive editor for manual modification:

    kubectl edit pod/nginx -o yaml
  • kubectl apply — updates the image tag in nginx.yaml, then reapplies the manifest:

    kubectl apply -f nginx.yaml

Step 4: Verify the update

  1. Check the pod's IP address again.

    kubectl get pod/nginx -n default -o wide

    The output shows that the pod IP address is still 172.16.22.193, unchanged from before the update.

    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>
  2. Confirm the image tag is updated.

    kubectl get pod/nginx -n default -o=custom-columns='IMAGE:spec.containers[*].image'

    Expected output:

    IMAGE
    nginx:1.9.6

    The unchanged IP address (172.16.22.193) and the new image tag (nginx:1.9.6) confirm that the update succeeded without affecting the pod's network identity.