且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ansible playbook 等待所有 Pod 运行

更新时间:2021-11-08 00:52:12

我会尝试这样的事情(对我有用):

I would try something like this (works for me):

tasks:
- name: wait for pods to come up
  shell: kubectl get pods -o json
  register: kubectl_get_pods
  until: kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]

您基本上是获取所有 Pod 的所有状态并将它们组合成一个唯一的列表,然后直到该列表是 ["Running"] 时它才会完成.因此,例如,如果您的所有 pod 都没有运行,您将得到类似 ["Running", "Starting"] 的信息.

You are basically getting all the statuses for all the pods and combining them into a unique list, and then it won't complete until that list is ["Running"]. So for example, if all your pods are not running you will get something like ["Running", "Starting"].