【问题标题】:Check Kubernetes Pod Status for Completed State检查 Kubernetes Pod 状态的已完成状态
【发布时间】: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


【解决方案1】:

已完成 pod 的正确 status.phaseSucceeded

因此,要仅过滤已完成的 pod,您应该使用:
kubectl get pod --field-selector=status.phase=Succeeded

虽然,不建议使用裸 pod。考虑使用Job Controller

一个 Job 创建一个或多个 Pod 并确保指定数量的 Pod 他们成功终止。随着 pod 成功完成,作业 跟踪成功完成。

您可以通过以下方式检查工作条件并等待它们:
kubectl wait --for=condition=complete job/myjob

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 2019-03-05
    • 1970-01-01
    • 2014-01-18
    相关资源
    最近更新 更多