VCI allows you to configure the startup and exit priorities of multiple containers in the same pod.
Background information
By default, containers within a VCI start and exit concurrently, with no fixed order. In some scenarios, dependencies may exist among multiple containers within a VCI. One container needs to start after another has started, or exit only after another has exited. For example, when collecting container logs, ensure the logging container has started and is in the Ready state before the business container generates logs. Also, ensure the logging container exits only after the business container has exited. For such scenarios, enable containers within a pod to start and exit based on specified priorities.
This feature applies to application containers within the same pod and does not apply to init containers or ephemeral containers. In the following content, containers refer to application containers unless otherwise specified.
Prerequisites
Configuring container startup priorities
To start containers within the same VCI in order, set the container startup priority in the pod. Containers with higher priority will start before those with lower priority. Containers with the same priority will start concurrently.
Parameter description
VCI allows you to configure container startup priorities by using environment variables. The following table describes the environment variables.
Example
The following content shows you how to create a VCI Deployment, where the pod contains two application containers. By setting the startup priority for each container and observing their start (started) time, the expected result is that the container with the higher priority will be started first. For instructions on creating a VCI, see Creating instances. - Create a YAML file for the VCI Deployment by using kubectl. The following vci-nginx-deployment.yaml file serves as an example:
- Run the following command to create the Deployment.
- The command in this example is as follows:
- After you create the Deployment, verify the container startup priority.
- Run the following command to obtain the name of the pod under the VCI Deployment.
- The command in this example is as follows:
- Obtain the pod name from the NAME field in the returned information.
- Run the following command to obtain the detailed information of the pod, and view the start time of each container in the Events field.
- The command in this example is as follows:
Configuring container exit priorities
To exit containers within the same VCI in order, set the container exit priority in the pod. Containers with higher priority will exit before those with lower priority. Containers with the same priority will exit concurrently.
Tip
If you configured the container exit priority, deleting a pod will take longer than the configured graceful deletion time.
Parameter description
VCI allows you to configure container exit priorities by using environment variables. The following table describes the environment variables.
Example
The following content provides an example of creating a VCI Deployment, where the pod contains two application containers. By setting the exit priority for each container, and configuring the pod's graceful deletion time to 90 seconds, you can observe the exit (killed) time of each container. The expected result is that the container with the higher exit priority will be killed first. For instructions on creating a VCI, see Creating instances.
- Create a YAML file for the VCI Deployment by using kubectl. The following vci-nginx-deployment.yaml file serves as an example:
- Run the following command to create the Deployment.
- The command in this example is as follows:
- After you create the Deployment, verify the container exit priority.
- Run the following command to obtain the name of the pod under the VCI Deployment.
- The command in this example is as follows:
- Obtain the pod name from the NAME field in the returned information.
- Run the following command to delete the pod, then quickly get its detailed information. Check the Event field of the pod to view the container kill sequence.
- The command in this example is as follows: