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.
The following example creates a Deployment named nginx. This Deployment has one pod, and an EIP is automatically assigned and bound to the pod. Table 1 describes the parameters.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "14"
description: ""
name: nginx
namespace: eip
spec:
...
replicas: 1
template:
metadata:
annotations:
yangtse.io/eip-id: 65eb3679-7a8d-4b24-b681-0b661axxxxcb
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 allocated. After the pod IP address is allocated, the container network controller binds an EIP to the pod and returns the allocation result to the annotation (yangtse.io/allocated-ipv4-eip) 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 check whether the EIP is allocated. You can configure the init container as follows:
apiVersion: v1
kind: Pod
metadata:
name: example
namespace: demo
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