简体   繁体   English

kubectl 等待 pod 完成

[英]kubectl wait for a pod to complete

I have a pod spec which runs a command like rm -rf /some/path我有一个 pod 规范,它运行像rm -rf /some/path这样的命令

i create the pod using kubectl apply -f ...我使用kubectl apply -f ...创建 pod kubectl apply -f ...

now i want to wait till the pod completes.现在我想等到吊舱完成。 i can see that the pod is done, kubectl get pod/<mypod> shows STATUS Completed我可以看到 pod 已完成, kubectl get pod/<mypod>显示STATUS Completed

How do i wait for this condition?我如何等待这种情况?

i have looked at kubectl wait ... but that doesnt seem to help me我看过kubectl wait ...但这似乎对我没有帮助

kubectl wait --for=condition=complete pod/<my-pod> seems to just block. kubectl wait --for=condition=complete pod/<my-pod>似乎只是阻止。 I havent deleted the pod, it is still there in the Completed status我还没有删除 pod,它仍然处于 Completed 状态

The command that you use: kubectl wait --for=condition=complete pod/<my-pod> will not work because a pod doesn't have such condition.您使用的命令: kubectl wait --for=condition=complete pod/<my-pod>将不起作用,因为 pod 没有这样的条件。 Pod Conditions are as follows: Pod条件如下:

  • PodScheduled : the Pod has been scheduled to a node. PodScheduled :Pod 已被调度到一个节点。

  • ContainersReady : all containers in the Pod are ready. ContainersReady :Pod 中的所有容器都已准备就绪。

  • Initialized : all init containers have started successfully. Initialized :所有初始化容器已成功启动。

  • Ready : the Pod is able to serve requests and should be added to the load balancing pools of all matching Services. Ready :Pod 能够处理请求,应该添加到所有匹配服务的负载平衡池中。

The phase for a successfully completed pod is called succeeded :成功完成 pod 的阶段称为succeeded

All containers in the Pod have terminated in success, and will not be restarted. Pod 中的所有容器都已成功终止,不会重新启动。

It would be better however if you use kubectl wait for Jobs instead of bare Pods and than execute kubectl wait --for=condition=complete job/myjob .但是,如果您使用kubectl wait for Jobs而不是裸 Pods 而不是执行kubectl wait --for=condition=complete job/myjob会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM