如何等到分配 EXTERNAL-IP?
How to wait until EXTERNAL-IP is assigned?
当我在我的 Digital Ocean K8S 集群上部署 https://projectcontour.io/ 入口控制器时,会自动创建一个负载均衡器。
我考虑使用Ansible作为K8S的管理工具来自动化部署。
完成以下任务后:
- name: retrieve file
get_url:
url: https://projectcontour.io/quickstart/contour.yaml
dest: /testing/contour.yaml
register: download_contour
- name: create deployment
k8s:
src: /testing/deployment.yml
when: download_contour.changed
我想等到 contour 获得分配的 EXTERNAL-IP 地址,然后继续其他任务。这是我本地计算机上的示例:
kubectl get -n projectcontour service envoy -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
envoy LoadBalancer 10.96.226.84 172.18.255.200 80:31092/TCP,443:30362/TCP 2d15h app=envoy
如何等待 envoy
LoadBalancer 获得在 Ansible 中分配的 EXTERNAL-IP 地址?
我还没有测试过,但我想你可以尝试这样做:
- shell: if [[ $(kubectl get services envoy -n projectcontour --output jsonpath='{.status.loadBalancer.ingress[0]}') ]]; then exit 0; else exit 1; fi;
register: wait_for_ext_ip
until: wait_for_ext_ip.rc == 0
retries: 10
delay: 5
您应该使用 until loops:
tasks:
- name: run kubectl to retreive external IP - Wait for task to complete
shell: "kubectl get -n projectcontour service envoy -o wide | awk '{ print }' | grep -v EXT"
register: k_ext_ip
until: k_ext_ip.stdout.find("1.2.3.4") != -1
retries: 6
delay: 10
对于shell命令,我只是简单地使用了一些基本的linux命令。最好用 Kubectl 对齐的命令替换那些以仅查看外部 IP。
当我在我的 Digital Ocean K8S 集群上部署 https://projectcontour.io/ 入口控制器时,会自动创建一个负载均衡器。
我考虑使用Ansible作为K8S的管理工具来自动化部署。
完成以下任务后:
- name: retrieve file
get_url:
url: https://projectcontour.io/quickstart/contour.yaml
dest: /testing/contour.yaml
register: download_contour
- name: create deployment
k8s:
src: /testing/deployment.yml
when: download_contour.changed
我想等到 contour 获得分配的 EXTERNAL-IP 地址,然后继续其他任务。这是我本地计算机上的示例:
kubectl get -n projectcontour service envoy -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
envoy LoadBalancer 10.96.226.84 172.18.255.200 80:31092/TCP,443:30362/TCP 2d15h app=envoy
如何等待 envoy
LoadBalancer 获得在 Ansible 中分配的 EXTERNAL-IP 地址?
我还没有测试过,但我想你可以尝试这样做:
- shell: if [[ $(kubectl get services envoy -n projectcontour --output jsonpath='{.status.loadBalancer.ingress[0]}') ]]; then exit 0; else exit 1; fi;
register: wait_for_ext_ip
until: wait_for_ext_ip.rc == 0
retries: 10
delay: 5
您应该使用 until loops:
tasks:
- name: run kubectl to retreive external IP - Wait for task to complete
shell: "kubectl get -n projectcontour service envoy -o wide | awk '{ print }' | grep -v EXT"
register: k_ext_ip
until: k_ext_ip.stdout.find("1.2.3.4") != -1
retries: 6
delay: 10
对于shell命令,我只是简单地使用了一些基本的linux命令。最好用 Kubectl 对齐的命令替换那些以仅查看外部 IP。