我们一般将pod对象从创建至终这段时间范围成为pod的生命周期,它主要包含以下的过程:
-
pod创建过程
-
运行初始化容器(init container)过程
-
运行主容器(main container)
---->容器启动后钩子(post start)、容器终止前钩子(pre stop)
---->容器的存活性检测(liveness probe)、就绪性检测(readiness probe)
-
pod终止过程
01Pod相位
首先在介绍 Pod 的生命周期之前,我们先了解下 Pod 的状态,因为 Pod 状态可以反映出当前我们的Pod 的具体状态信息,也是我们分析排错的一个必备的方式。
我们可以通过命令kubectl explain pod.status查看到
[root@master ~]# kubectl explain pod.status
KIND: Pod
VERSION: v1
.....
phase <string>
The phase of a Pod is a simple, high-level summary of where the Pod is in
its lifecycle. The conditions array, the reason and message fields, and the
individual container status arrays contain more detail about the pod's
status. There are five possible phase values:
Pending: The pod has been accepted by the Kubernetes system, but one or
more of the container images has not been created. This includes time
before being scheduled as well as time spent downloading images over the
network, which could take a while. Running: The pod has been bound to a
node, and all of the containers have been created. At least one container
is still running, or is in the process of starting or restarting