gpt4 book ai didi

kubernetes - 检查 Kubernetes Pod 状态的已完成状态

转载 作者:行者123 更新时间:2023-12-03 20:47:03 25 4
gpt4 key购买 nike

有没有办法检查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
数据加载 pods 1/1 运行 0 5m

待办的:

[user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Pending -n mynamespace
姓名准备状态重新开始年龄
app-deployment-0 0/1 待定 0 5m

完全的:

[user@sandbox gcp_kubernetes_installation]$ kubectl get pod -n 命名空间
姓名准备状态重新开始年龄
mssql-deployment-795dfcf9f7-l2b44 1/1 运行 0 11m
data-load-data-load-pod 0/1 已完成 0 10m
app-deployment-0 0/1 待定 0 10m
[user@sandbox gcp_kubernetes_installation]$ kubectl get pods --field-selector=status.phase=Completed -n 命名空间
没有找到资源。

我相信字段选择器中可能存在错误,但只是想知道是否有任何修复或解决方法的详细信息。

最佳答案

已完成 Pod 的正确 status.phase 是 成功 .

因此,要仅过滤已完成的 pod,您应该使用:kubectl get pod --field-selector=status.phase=Succeeded
但是,不建议使用裸 Pod。考虑使用 Job Controller :

A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions.



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

关于kubernetes - 检查 Kubernetes Pod 状态的已完成状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55184779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com