简体   繁体   English

使用 kubectl 等待 pvc 被绑定

[英]Using kubectl to wait until a pvc is bound

I wanna use kubectl wait command to wait until a pvc is bound.我想使用kubectl wait命令等到 pvc 绑定。

I tried kubectl wait --for=condition=bound pvc/my-pvc-claim --timeout=2s with a pvc which is already bound, but it doesn't seem to work.我用已经绑定的 pvc 尝试kubectl wait --for=condition=bound pvc/my-pvc-claim --timeout=2s ,但它似乎不起作用。 This is the output error: timed out waiting for the condition on persistentvolumeclaims/my-pvc-claim .这是 output error: timed out waiting for the condition on persistentvolumeclaims/my-pvc-claim

I read kubectl wait documentation, but still can't understand which condition I should use.我阅读kubectl wait文档,但仍然无法理解我应该使用哪个条件。 How can I accomplish that?我怎样才能做到这一点? Is there a more complete documentation explaining how to do that?是否有更完整的文档解释如何做到这一点?

You can use the following command:您可以使用以下命令:

while [[ $(kubectl get pvc myclaim -o 'jsonpath={..status.phase}') != "Bound" ]]; do echo "waiting for PVC status" && sleep 1; done

You may want to try using explain to see what conditions are possible to make sure you have the right one.您可能想尝试使用 explain 来查看哪些条件可以确保您拥有正确的条件。 Check here for an example of how you might use that. 查看此处以获取有关如何使用它的示例。

Use the jsonpath provided in subudears answer as the for option.使用 subudears 答案中提供的 jsonpath 作为 for 选项。 So this way you can utilise kubectl wait所以这样你就可以利用kubectl wait

kubectl wait --for=jsonpath='{.status.phase}'=Bound pvc/my-pvc

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

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