Help Center> Cloud Container Engine> FAQ> Reference> How Can Container IP Addresses Survive a Container Restart?

How Can Container IP Addresses Survive a Container Restart?

If Containers Will Run in a Single-Node Cluster

Add hostNetwork: true to the spec.spec. in the YAML file of the workload to which the containers will belong.

The detailed procedure is as follows:

  1. Log in to the CCE console.
  2. In the navigation pane, choose Workloads > Deployments and click Create Deployment.

    In this example, there is only one node in the cluster. Therefore, Instances (the quantity of pods that the Deployment will have) on the Create Deployment page must be set to 1. Otherwise, multiple pods with the same IP address will be created.

  3. In the upper right corner of the Configure Advanced Settings page, click Create YAML.
  4. Add hostNetwork: true to spec.spec. in the YAML file, as shown in Figure 1.

    Figure 1 Editing a workload's YAML file

  5. Click Create. After the workload is created, choose View Workload Details. In the pod list, you can see that the pod IP address is the same as the IP address of the node where the workload is located.

    Figure 2 Viewing pod and node IP addresses

If Containers Will Run in a Multi-Node Cluster

Configure node affinity policies, in addition to perform the operations described in "If the Container Runs in a Single-Node Cluster". However, after the workload is created, the number of running pods cannot exceed the number of affinity nodes.

The detailed procedure is as follows:

  1. On the workload details page, choose Scheduling Policies and click Add Simple Scheduling Policy.
  2. Click Add Affinity Object.
  3. In the displayed Add Affinity Object dialog box, set Object Type to Node, select the nodes where the workload is eligible to run, and click OK.
Figure 3 Adding a node affinity policy

Expected Result

After the previous settings are complete and the workload is running, the IP addresses of the workload's pods are the same as the node IP addresses. After the workload is restarted, these IP addresses will keep unchanged.