Updated on 2025-09-26 GMT+08:00

Binding a New EIP to a Pod

Assigning 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 pod named nginx as an example. For details about the parameters, see Table 1.

  • To create a pod 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 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: "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.

  • 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 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:

  • 5_bgp: dynamic BGP
  • 5_sbgp: static BGP

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).

  • 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 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 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 of an EIP with a shared bandwidth

Parameter

Mandatory

Description

Range

yangtse.io/pod-with-eip

Yes

Whether to bind an EIP to a pod.

  • 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 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:

  • 5_bgp: dynamic BGP
  • 5_sbgp: static BGP

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 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: 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 created with it is also deleted. You can run the following command to delete a pod using ccictl:

# ccictl delete pod $pod_name -n $namespace_name