Binding a New EIP to a Pod
Allocating an EIP During Pod Creation
When creating a pod, configure pod-with-eip under annotations. An EIP is automatically assigned and bound to the pod.
The following uses a Deployment named nginx as an example. For details about the parameters, see Table 1.
- To create a Deployment that uses a dedicated bandwidth, you do not need to specify the bandwidth ID.
apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "14" description: "" name: nginx namespace: eip spec: ... template: metadata: 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"
- To create a Deployment that uses a shared bandwidth, you must and only need to specify the bandwidth ID.
apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "14" description: "" name: nginx namespace: eip spec: ... template: metadata: annotations: yangtse.io/pod-with-eip: "true" yangtse.io/eip-bandwidth-id: "xxx"
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 check whether the EIP is assigned. For details about the parameters, see Table 1. You can configure the init container as follows:

CCI allows EIPs to be automatically bound to pods. EIPs are assigned after pod scheduling is complete. EIP annotations cannot be injected to pods through ENV.
apiVersion: v1 kind: Pod metadata: name: example namespace: demo 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']
Parameter |
Mandatory |
Description |
Value |
---|---|---|---|
yangtse.io/pod-with-eip |
Yes |
Whether to bind an EIP to a pod |
|
yangtse.io/eip-bandwidth-size |
No |
Bandwidth, in Mbit/s |
The default value is 5. The types vary by region. For details, see the EIP console. |
yangtse.io/eip-network-type |
No |
EIP type |
The default value is 5_bgp. If your region does not support 5_bgp and this parameter is left empty, an event is reported for the pod. The types vary by region. For details, see the EIP console. For example, the following types are supported in the CN East-Shanghai1 region:
|
yangtse.io/eip-charge-mode |
No |
Billed by traffic or bandwidth You are advised to configure this parameter. If this parameter is left blank, no billing mode is specified. In this case, the default value of the EIP API in the region is used. |
The value can be bandwidth (default) or traffic (optional).
|
yangtse.io/eip-bandwidth-id |
Yes (for shared bandwidths) |
Shared bandwidth ID |
If you have set this parameter, you do not need to set other values. |
yangtse.io/eip-bandwidth-name |
No |
Bandwidth name |
The default value is the same as the EIP name.
|
Releasing an EIP During Pod Deletion
When you delete a pod, the EIP bound to it is also released. You can run the following command to delete a pod:
# kubectl delete pod nginx -n $namespace_name
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