ansible kubectl 等待节点就绪

Dar*_*Var 6 ansible kubernetes

是否有任何现有的 ansible 模块可以用于以下用途。我可以等kubectl get nodes STATUS= Ready

$ kubectl get nodes
NAME      STATUS     ROLES     AGE       VERSION
master1   NotReady   master    42s       v1.8.4
Run Code Online (Sandbox Code Playgroud)

Anj*_*yna 10

命令kubectl wait

Kubernetes从 v1.11 版本开始支持使用kubectl wait 。
它等待一个或多个资源的特定条件。

将 kubectl wait 命令与 ansible 任务一起使用:

  - name: Wait for all k8s nodes to be ready
    shell: kubectl wait --for=condition=Ready nodes --all --timeout=600s
    register: nodes_ready

  - debug: var=nodes_ready.stdout_lines
Run Code Online (Sandbox Code Playgroud)

如果您只想检查某些特定节点的条件,可以使用 a--selector代替,--all如下所示:

  - name: Wait for k8s nodes with node label 'purpose=test' to be ready
    shell: kubectl wait --for=condition=Ready nodes --selector purpose=test --timeout=600s
    register: nodes_ready

  - debug: var=nodes_ready.stdout_lines
Run Code Online (Sandbox Code Playgroud)


sfg*_*ups 3

我不知道任何现有的模块。你可以做这样的事情。

---
- hosts: localhost
  gather_facts: no
  tasks:
  - name: Wait for nodes to be ready
    shell: "/usr/bin/kubectl get nodes"
    register: nodes
    until:      
      - '" Ready "  in nodes.stdout'      
    retries: 6
    delay: 2
Run Code Online (Sandbox Code Playgroud)