Kubernetes1.3:pod Life Cycle Management

Source: Internet
Author: User

(i) Core Concepts

Pod is the core concept in Kubernetes, kubernetes management of Pod is the management of Pod lifecycle, the management of pod life cycle is the management of pod State, We can analyze how the pod state is managed by kubernetes the various entity information graphs associated with pod below.


(ii) Introduction to the structure

Pod in this structure has a variable status, through this variable can get the state information of each pod, the status variable corresponding to the structure is podstatus, from the graph can be seen in the pod state information with four variables, respectively, phase, Conditions , Initcontainerstatuses, and containerstatuses, these four variables represent the lifecycle phase of the pod, the conditions that the pod lifecycle needs to meet, all the initialization container states in the pod, and all application container states in the pod.

The variable phase has five optional values, namely, pending, Running, succeeded, failed, and unknown.


The meanings of this five values are:

1 pending:kubernetes has started creating pod, but one or more containers in the pod have not yet been started. For example, Pod is in the scheduling process that should be assigned to which node, or kubernetes is downloading the pod container mirroring from the mirrored warehouse.

2 Running:kubernetes has already allocated pod to the node, and all containers in the pod have been started. It also includes at least one container in the pod that is still running, or is restarting the state.

3 All containers in the succeeded:pod are in the terminating state, and the containers are exited to the termination state normally, that is, the exit code is 0, and Kubernetes does not reboot any containers.

4 All containers in Failed:pod are terminated, and at least one container is not terminated normally, that is, the exit code is not 0, or the system is forced to terminate.

5) Unknown: Unable to obtain pod status due to some special circumstances, such as inability to communicate with pod host for network reasons.

The value of the variable phase also depends on the restartpolicy variable in the podspec of the struct, which is used to set the container restart strategy in the pod, including three optional values, always, onfailure, and never respectively.


The three worthwhile meanings are:

1) Always: Indicates that a restart policy has been performed on the container. If you do not set Restartpolicy, then always is the default value.

2) OnFailure: means to reboot the container when the container fails.

3) Never: Indicates that no restart policy is performed on the container.

The variable conditions corresponds to the structural body podcondition, in which there are two variable type and status. The variable type represents a valid condition type, and the status of the variable represents the corresponding state for each type.

The variable type has three optional values, namely podscheduled, ready, and initialized.


The meanings of these three values are:

1) podscheduled: Indicates that pod is in the process of dispatch.

2) Ready: Indicates that pod has been able to provide services.

3) Initialized: Indicates that all of the initialization containers in the pod have been successfully started.

The variable status represents the state for each type, with three optional values, true, false, and unknown respectively.


The meanings of these three values are:

1 True: Indicates that the pod is in a valid condition of some kind.

2) False: Indicates that the pod is not in a valid condition of some kind.

3) Unknown: Indicates that kubernetes cannot determine whether pod is in a valid condition of a certain type.

The variable initcontainerstatuses and containerstatuses correspond to the structural body Containerstatus, recording all the initialization container states and all application container states in the pod, The structure body Containerstatus represents the state of a container in which the variable state represents the current status of the container, and the variable states corresponds to the structure containerstate. The structure body containerstate consists of three variables waiting, running and terminated, respectively representing the waiting state, the running state and the end state, and the three variables in the structure containerstate can only have one in the active state. If you cannot determine which is left, then the wait state is selected.


The variable terminated corresponds to the structure body containerstateterminated, the structure body containerstateterminated has a variable exitcode, through this variable to record the container exit code mentioned above, If the container exits normally, the exit code is 0, otherwise it is a different value.

(iii) Setting the pod lifecycle

Set the pod lifecycle, which is to set the value of the variable phase in the structure body podstatus, the following flowchart shows how to set the value of the variable phase.


In the pod of kubernetes1.3, there are two kinds of containers, one is the System container (pod Container), the other is the user container, which in the user container, is now divided into two kinds of containers, one is the initialization container (init Container), a class of application containers (app Container), set pod lifecycle needs to be used in user containers.

First check all the initialization container states in the pod, then check all the application container states in the pod, then set the pod lifecycle based on the two types of container state and Restartpolicy.

The following are examples of Pod lifecycle settings based on specific conditions:

1. If there is any initialization container in the pod, when the initialization state is terminated and the initialization container exits abnormally, that is, the exit code is not 0, and Restartpolicy is never, then the pod lifecycle is failed.

2. If there is any initialization container in the pod, when the initialization container state is waiting, and the last stop state of the initialization container is not empty, that is, the lastterminationstate is not empty, and the initialization container last time was abnormally exited, That is, the exit code is not 0, and Restartpolicy is never, then the pod lifecycle is failed.

3. If there is any application container in the pod, the pod lifecycle is pending when the application container state is waiting and the last state of the application container is empty, that is, Lastterminationstate is empty. That is, the pod lifecycle is pending when there are application containers in the pod that do not begin to run.

4. If none of the application containers in the pod have a waiting state, or an application container with a waiting state in the pod, the last termination state of these application containers is not NULL, if one of the above conditions is met, and there is an application container for the running state in the pod, Then the pod life cycle is running. That is, the pod lifecycle is running when all the application containers in the pod are in a normal startup state, and there is an application container in which the state is running.

5. If there is no application container for the running state in the pod, when this condition is met, if there is a terminated state in the pod, or an application container with a waiting state in the pod, and the last stop state of the application container is not empty, At this point, if the restartpolicy is always, then the pod lifecycle is running, which means that all the application containers in the pod have a reboot state, and if Restartpolicy is not always, then if all the application containers are terminated properly, So the pod lifecycle is succeeded, and if Restartpolicy is never, if a container is in a failed state, the pod lifecycle is failed, and if Restartpolicy is OnFailure, So if a container is in a reboot failure state, the pod lifecycle is running.

6. If none of the above conditions are met, then the pod lifecycle is in pending state by default.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.