云容器引擎 CCE-为Pod配置EIP:检查Pod的EIP就绪

时间:2023-12-18 08:59:37

检查Pod的EIP就绪

容器网络控制器会在Pod IP分配后,为Pod绑定EIP并回写分配结果至Pod的annotation(yangtse.io/allocated-ipv4-eip),Pod业务容器的启动时间可能早于EIP分配结果回写成功时间。

您可以尝试为Pod配置init container并使用downwardAPI类型的存储卷把yangtse.io/allocated-ipv4-eip的annotation通过volume挂载到init container里,并在init container中检查EIP是否已经分配成功。您可以参考以下示例配置init container。

apiVersion: v1
kind: Pod
metadata:
  name: example
  annotations:
    yangtse.io/pod-with-eip: "true"  
    yangtse.io/eip-bandwidth-size: "5" 
    yangtse.io/eip-network-type: 5_bgp
    yangtse.io/eip-charge-mode: bandwidth
    yangtse.io/eip-bandwidth-name: "xxx"
spec:
  initContainers:
  - name: init
    image: busybox:latest
    command: ['timeout', '60', 'sh', '-c', "until grep -E '[0-9]+' /etc/eipinfo/allocated-ipv4-eip; do echo waiting for allocated-ipv4-eip; sleep 2; done"]
    volumeMounts:
        - name: eipinfo
          mountPath: /etc/eipinfo
  volumes:
    - name: eipinfo
      downwardAPI:
        items:
          - path: "allocated-ipv4-eip"
            fieldRef:
              fieldPath: metadata.annotations['yangtse.io/allocated-ipv4-eip']
...
support.huaweicloud.com/usermanual-cce/cce_10_0734.html