原文: http://www.knockatdatabase.com/2022/05/21/kubernetes-pod-phase-and-pod-conditions/
用于描述、查看、分析 pod 当前处于什么状态。
通常情况下,在 pod 的生命周期中,每个 pod 会处于 5 个不同的 phase:pending,running,succeed,failed,unknown。同一时间,1 个 pod 只能处于 1 个 phase。
由于 pod 的 phase 字段位于 pod 的 manifest 中的 Status 部分,也就是说 ,我们可以从 Kubernetes API server 那里获取 pod 的 yaml 文件,然后从 status 字段中找到 pod 的 phase。那么,我们就可以,通过 kubectl get pod pod_name -o yaml|grep phase 来查看 pod 的 phase:
[root@master-node ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
curl 1/1 Running 0 6d9h
curl-with-ambassador 2/2 Running 0 28d
downward 1/1 Running 0 28d
fortune-configmap-volume 2/2 Running 0 36d
fortune-https 2/2 Running 0 35d
my-job-jfhz9 0/1 Completed 0 6d9h
[root@master-node ~]# kubectl get pods curl -o yaml|grep phase
phase: Running
[root@master-node ~]# kubectl get pods my-job-jfhz9 -o yaml|grep phase
phase: Succeeded
[root@master-node ~]#
从上,我们通过 pod 的 yaml 文件里获取了它们的 phase。其中的 my-job-jfhz9 是一个 job 且已经执行完成。所以,它处于 succeed 的 phase。
因为 pod 的 phase 比较简单的描述了 pod 处于哪个具体情况,但是没有明确说明具体原因。
用于描述 1 个 pod 当前是否处于哪个 phase,以及处于该 phase 的原因。及作为一个辅助手段,详细的展示 pod 的状态信息,用于问题排查分析时提供更多依据。同一时间,1 个 pod 可能处于多个 conditions。
通常分为 4 个 conditions:PodScheduled,Initialized,ContainersReady,Ready。见名知意:
同样,由于 pod 的 conditions 源于 yaml 格式的 manifest 中的 Status 字段,我们可以从 yaml 文件里查看。
[root@master-node ~]# kubectl get pods curl -o yaml
apiVersion: v1
kind: Pod
...
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:23:37Z"
status: "True"
type: Initialized #conditions状态2
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:23:51Z"
status: "True"
type: Ready #conditions状态4
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:23:51Z"
status: "True"
type: ContainersReady #conditions状态3
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:23:37Z"
status: "True"
type: PodScheduled #conditions状态1
containerStatuses:
- containerID: docker://9d56be349349b7581a4178b11895167b5be8c1c68ce1630f440389a1e8257a35
image: docker.io/rancher/curl:latest
imageID: docker-pullable://docker.io/rancher/curl@sha256:85aea1846e2e9b921629e9c3adf0c5aa63dbdf13aa84d4dc1b951982bf42d1a4
lastState: {}
name: main
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2022-05-09T15:23:50Z"
hostIP: 172.16.11.161
phase: Running
podIP: 10.244.2.245
podIPs:
- ip: 10.244.2.245
qosClass: BestEffort
startTime: "2022-05-09T15:23:37Z"
[root@master-node ~]#
从上,我们可以从 yaml 中的 Status 字段里的 conditions 字段看到 pod 的 4 个 conditions。
同样,我们也可以通过 kubectl describe pod 来获取 conditions:kubectl describe pod pod_name|grep Conditions: -A 5
[root@master-node ~]# kubectl describe pod curl|grep Conditions: -A 5
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
[root@master-node ~]# kubectl describe pod my-job-jfhz9|grep Conditions: -A5
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
[root@master-node ~]#
表示要过滤 Conditions:字段,然后,-A5 表示紧随其后的 5 行。-A 5 之间也可以留空格,不影响结果。
比如:上述我们看到的类型为 job 的 pod my-job-jfhz9 它的 conditions 中,有多个是 False 的。为什么呢?我们同样,可以从 kubectl get pods pod_name -oyaml 里查看到类似下述的说明信息:
conditions:
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:22:23Z"
reason: PodCompleted
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:24:44Z"
reason: PodCompleted
status: "False"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:24:44Z"
reason: PodCompleted
status: "False"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2022-05-09T15:22:19Z"
status: "True"
type: PodScheduled
我们,从 reason 字段里,看到 pod 处于某个状态下的具体原因。原来,ContainersReady 的状态为 false 的原因,是 PodCompleted 了。
其中的 lastProbeTime 表示的该 conditions 在什么时间被检查过,名字中虽然有 probe,但是它跟 probe 没有关系; lastTransitionTime 表示该 conditions 在什么时间点儿发生的变化;
- END -
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有