In Cloud Native Network 2.0, pods use VPC ENIs or sub-ENIs for networking. You can directly bind EIPs to pods.
To associate an EIP with a pod, simply set the value of the yangtse.io/pod-with-eip annotation to true when creating the pod. Then, the EIP will be automatically allocated and bound to the pod.
A CCE Turbo cluster is available and the cluster version meets the requirements listed in the following table.
Scenario |
Cluster Version |
---|---|
Allocating an EIP with a pod |
|
Using an existing EIP for a pod |
v1.23: v1.23.16-r0 or later v1.25: v1.25.11-r0 or later v1.27: v1.27.8-r0 or later v1.28: v1.28.6-r0 or later v1.29: v1.29.2-r0 or later Versions later than v1.29 |
If you set the pod-with-eip annotation to true when creating a pod, 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.
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: 100m memory: 200Mi requests: cpu: 100m memory: 200Mi imagePullSecrets: - name: default-secret
Annotation |
Mandatory |
Default Value |
Description |
Value Range |
---|---|---|---|---|
yangtse.io/pod-with-eip |
Yes |
false |
Whether to allocate an EIP with a pod and bind the EIP to the 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 EIP console. |
yangtse.io/eip-network-type |
No |
5_bgp |
EIP type |
The type varies depending on the region. For details, see on the EIP console. |
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. |
|
yangtse.io/eip-bandwidth-name |
No |
Pod name |
Bandwidth name |
|
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: 100m memory: 200Mi requests: cpu: 100m memory: 200Mi imagePullSecrets: - name: default-secret
Annotation |
Mandatory |
Default Value |
Description |
Value Range |
---|---|---|---|---|
yangtse.io/pod-with-eip |
Yes |
false |
Whether to allocate an EIP with a pod and bind the EIP to the pod |
false or true |
yangtse.io/eip-network-type |
No |
5_bgp |
EIP type |
The specific type varies with regions. For details, see the EIP console. |
yangtse.io/eip-bandwidth-id |
Mandatory when a shared bandwidth is used |
None |
ID of an existing bandwidth
|
None |
If you configure the yangtse.io/eip-id annotation when creating a pod, the EIP will be automatically bound to the pod.
The following example shows how to create a Deployment named nginx with a single pod with an EIP automatically bound.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
annotations:
yangtse.io/eip-id: <eip_id> # ID of an existing EIP
spec:
containers:
- name: container-0
image: nginx:alpine
resources:
limits:
cpu: 100m
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
imagePullSecrets:
- name: default-secret
Annotation |
Mandatory |
Description |
---|---|---|
yangtse.io/eip-id |
Yes |
EIP ID How to obtain: Log in to the EIP console, click the name of the target EIP in the EIP list, and copy the ID field. |
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'] ...