How Can Container IP Addresses Survive a Container Restart?
Scenarios and Expected Results
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:
- Log in to the CCE console.
- 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.
- In the upper right corner of the Configure Advanced Settings page, click Create YAML.
- Add hostNetwork: true to spec.spec. in the YAML file, as shown in Figure 1.
- 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:
- On the workload details page, choose Scheduling Policies and click Add Simple Scheduling Policy.
- Click Add Affinity Object.
- 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.

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.