Configuring an EIP for a Pod
Scenario
In CCE Autopilot clusters, pods use elastic network interfaces or supplementary network interfaces for networking so you can directly bind EIPs to pods.
To bind an EIP to a pod, simply set the value of the yangtse.io/pod-with-eip annotation to true when creating the pod. Then, the EIP is automatically allocated and bound to the pod.
Constraints
- To access a pod with an EIP bound from the Internet, you need to add security group rules to allow the Internet traffic to the pod.
- Only one EIP can be bound to a pod.
- Configure the EIP-related annotation when creating a pod. After the pod is created, the annotations related to the EIP cannot be modified.
- Do not perform operations on the EIP associated with a pod through the EIP console or API. Otherwise, the EIP may malfunction. The operations include changing the EIP name, deleting, unbinding, or binding the EIP, and changing the billing mode of the EIP.
- After an automatically allocated EIP is manually deleted, the network malfunctions. In this case, rebuild the pod.
Allocating an EIP with a Pod
When creating a pod, set the pod-with-eip annotation to true. An EIP will be automatically allocated and bound to the pod.
The following uses a Deployment named nginx as an example. For details about annotations, see Table 2.
- For an automatically allocated EIP with a dedicated bandwidth when you create a Deployment, you do not need to specify the bandwidth ID. The following shows an example:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx annotations: yangtse.io/pod-with-eip: "true" # An EIP will be automatically allocated when the pod is created. yangtse.io/eip-bandwidth-size: "5" # EIP bandwidth yangtse.io/eip-network-type: 5_bgp # EIP type yangtse.io/eip-charge-mode: bandwidth # EIP billing mode yangtse.io/eip-bandwidth-name: <eip_bandwidth_name> # EIP bandwidth name spec: containers: - name: container-0 image: nginx:alpine resources: limits: cpu: 250m memory: 500Mi requests: cpu: 250m memory: 500Mi imagePullSecrets: - name: default-secret
Table 1 Annotations of an EIP with a dedicated bandwidth Annotation
Mandatory
Default Value
Description
Value Range
yangtse.io/pod-with-eip
Yes
false
Whether to bind an EIP to a pod
false or true
yangtse.io/eip-bandwidth-size
No
5
Bandwidth, in Mbit/s
The value range varies depending on the region and bandwidth billing mode. For details, see the purchase page on the EIP console.
For example, in the AP-Singapore region, if an EIP is billed by bandwidth, the bandwidth ranges from 1 Mbit/s to 2,000 Mbit/s; if an EIP is billed by traffic, the bandwidth ranges from 1 Mbit/s to 300 Mbit/s.
yangtse.io/eip-network-type
No
5_bgp
EIP type
The types vary by region. For details, see the EIP console.
For example, the following options are available in the AP-Singapore region:
- 5_bgp: dynamic BGP
yangtse.io/eip-charge-mode
No
None
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.
- bandwidth: billed by bandwidth
- traffic: billed by traffic
yangtse.io/eip-bandwidth-name
No
Pod name
Bandwidth name
- Enter 1 to 64 characters. Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed.
- Minimum length: 1 character
- Maximum length: 64 characters
- For an automatically allocated EIP with a shared bandwidth when you create a Deployment, you are required to specify the bandwidth ID. The following shows an example:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx annotations: yangtse.io/pod-with-eip: "true" # An EIP will be automatically allocated when the pod is created. yangtse.io/eip-network-type: 5_bgp # EIP type yangtse.io/eip-bandwidth-id: <eip_bandwidth_id> # Shared bandwidth ID of the EIP spec: containers: - name: container-0 image: nginx:alpine resources: limits: cpu: 250m memory: 500Mi requests: cpu: 250m memory: 500Mi imagePullSecrets: - name: default-secret
Table 2 Annotations of an EIP with a shared bandwidth Annotation
Mandatory
Default Value
Description
Value Range
yangtse.io/pod-with-eip
Yes
false
Whether to bind an EIP to a pod
false or true
yangtse.io/eip-network-type
No
5_bgp
EIP type
yangtse.io/eip-bandwidth-id
Mandatory when a shared bandwidth is used
None
ID of an existing bandwidth
- If this parameter is not specified, the EIP with a dedicated bandwidth is used by default. For details about parameter settings for an EIP with a dedicated bandwidth, see Table 1.
- Only the yangtse.io/eip-network-type field can be specified concurrently, and this field is optional.
-
Checking Whether the EIP Bound to the Pod Is Available
After an EIP is allocated to a pod, the container networking controller binds the EIP to the pod and writes the allocation result back to the pod's yangtse.io/allocated-ipv4-eip annotation. The startup time of the pod's service containers may be earlier than the time when the EIP allocation result is written back.
You can configure an init container for the pod, associate the yangtse.io/allocated-ipv4-eip annotation with the init container through a downwardAPI volume, and check whether the EIP has been allocated in the init container. You can configure the init container as follows:
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'] ...
Deleting an EIP with a Pod
When you delete a pod, the EIP automatically allocated to the pod will also be deleted.
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