Binding an Existing EIP to a Pod
Specifying the EIP ID for a Pod
When creating a pod, enter the yangtse.io/eip-id annotation. An EIP is automatically assigned and bound to the pod.
In the following example, a pod named nginx is created, and an EIP is automatically assigned and bound to the pod. Table 1 describes the parameters.
kind: Pod apiVersion: cci/v2 metadata: name: nginx namespace: ns-test annotations: yangtse.io/eip-id: 65eb3679-7a8d-4b24-b681-0b661axxxxcb spec: containers: - name: container1 image: nginx:stable-alpine-perl resources: limits: cpu: '1' memory: 2G requests: cpu: '1' memory: 2G terminationMessagePath: /dev/termination-log terminationMessagePolicy: File restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: Default securityContext: {} imagePullSecrets: - name: imagepull-secret
Verifying the EIP Allocation
The startup time of the pod may be earlier than the time when the EIP allocation result is returned. During pod startup, the EIP may fail to be bound.
You can use an init container to check whether the EIP is assigned. After the pod IP address is assigned, the container network controller binds an EIP to the pod and returns the allocation result to the yangtse.io/allocated-ipv4-eip annotation of the pod. You can configure an init container in the pod and use the downward API to mount the annotation to the init container through a volume to verify that the EIP has been assigned. You can configure the init container as follows:
kind: Pod
apiVersion: cci/v2
metadata:
name: nginx
namespace: ns-test
annotations:
yangtse.io/eip-id: 65eb3679-7a8d-4b24-b681-0b661axxxxcb
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']
...
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot