Updated on 2026-04-28 GMT+08:00

Binding a New EIP to a Pod

Assigning an EIP During Pod Creation

If you configure the pod-with-eip annotation when creating a pod, an EIP will be automatically assigned and bound to the pod.

The following uses a pod named nginx as an example. For details about the parameters, see Table 1.

  • To create a pod with an EIP that uses a dedicated bandwidth, you do not need to specify the bandwidth ID.
    kind: Pod
    apiVersion: cci/v2
    metadata:
      name: nginx
      namespace: ns-test
      annotations:
        yangtse.io/pod-with-eip: "true"        # An EIP will be automatically assigned when the pod is being created.
        yangtse.io/eip-bandwidth-size: "5"     # EIP bandwidth.
        yangtse.io/eip-network-type: 5_bgp     # EIP type
        yangtse.io/eip-charge-mode: traffic  # EIP billing mode
        yangtse.io/eip-bandwidth-name: "xxx"   # Bandwidth name
    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
Table 1 Annotations for an EIP with a dedicated bandwidth

Parameter

Mandatory

Description

Range

yangtse.io/pod-with-eip

Yes

Whether to bind an EIP to a pod during pod creation

  • false: This option is disabled.
  • true: This option is enabled.

yangtse.io/eip-bandwidth-size

No

Bandwidth, in Mbit/s

The default value is 5. The bandwidth varies by region. You can view the bandwidth on the purchase page of 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 an empty string, an event will be reported for the pod. The types vary by region. You can view available types on the purchase page of the EIP console.

yangtse.io/eip-charge-mode

No

Whether the bandwidth is 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.

  • bandwidth: billed by bandwidth
  • traffic: billed by traffic

yangtse.io/eip-bandwidth-name

No

Bandwidth name

The default value is the same as the EIP name.

  • The name contains 1 to 64 characters. Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed.
  • Minimum characters: 1
  • Maximum characters: 64
  • To create a pod with an EIP that uses a shared bandwidth, you must and only need to specify the bandwidth ID.
     
    kind: Pod
    apiVersion: cci/v2
    metadata:
      name: nginx
      namespace: ns-test
      annotations:
        yangtse.io/pod-with-eip: "true"  # An EIP will be automatically assigned when the pod is being created.
        yangtse.io/eip-bandwidth-id: "5xxxxxx4-a801-4bfd-9004-5fxxxxxxxx19" # EIP shared bandwidth ID
    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
Table 2 Annotations for an EIP with a shared bandwidth

Parameter

Mandatory

Description

Range

yangtse.io/pod-with-eip

Yes

Whether to bind an EIP to a pod during pod creation

  • false: This option is disabled.
  • true: This option is enabled.

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-network-type

No

EIP type

The default value is 5_bgp. If your region does not support 5_bgp and this parameter is an empty string, an event will be reported for the pod. The types vary by region. You can view available types on the purchase page of the EIP console.

Verifying the EIP Readiness

The startup time of the pod may be earlier than the time when the EIP assignment 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 assignment result to the yangtse.io/allocated-ipv4-eip annotation of the pod. You can configure an init container in the pod and use the downwardAPI to mount the annotation to the init container through a volume to verify that the EIP has been assigned. For details about the parameters, see Table 2. 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.

kind: Pod
apiVersion: cci/v2
metadata:
  name: nginx
  namespace: ns-test
  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: traffic
    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']
...

Releasing an EIP with a Pod

When you delete a pod, the EIP created with it is also released. You can run the following command to delete a pod using ccictl:

# ccictl delete pod $pod_name -n $namespace_name