【发布时间】:2019-08-06 15:53:01
【问题描述】:
有没有办法检查 pod 状态是否处于已完成状态?我有一个只想使用一次的 Pod(其中 init 容器不能完全满足我的目的),并且想写一个检查以等待 Completed 状态。
我可以在 Running、Pending 中获得它,但在 Completed 中无法获得它。
跑步:
[user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Running -n mynamespace 名称 就绪 状态 重新开始 年龄 mssql-deployment-795dfcf9f7-l2b44 1/1 运行 0 6m data-load-pod 1/1 运行 0 5m待定:
[user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Pending -n mynamespace 名称 就绪 状态 重新开始 年龄 应用部署-0 0/1 待定 0 5m已完成:
[user@sandbox gcp_kubernetes_installation]$ kubectl 获取 pod -n 命名空间 名称 就绪 状态 重新开始 年龄 mssql-deployment-795dfcf9f7-l2b44 1/1 运行 0 11m data-load-data-load-pod 0/1 完成 0 10m 应用部署-0 0/1 待定 0 10m [user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Completed -n namespace 没有找到资源。我认为字段选择器中可能存在错误,但只是想知道是否有任何修复或解决方法的详细信息。
【问题讨论】:
-
我认为最好的选择是使用 Job 控制器而不是裸 pod,并使用
kubectl wait等待 Job 完成 条件。看看this answer。
标签: kubernetes