Changing a Custom EIP for a LoadBalancer Service
You can customize the EIP bound to a load balancer that is automatically created by CCE by adding the kubernetes.io/elb.custom-eip-id annotation to a Service.
Prerequisites
- A Kubernetes cluster is available and the cluster version meets the following requirements:
- v1.23: v1.23.18-r0 or later
- v1.25: v1.25.13-r0 or later
- v1.27: v1.27.10-r0 or later
- v1.28: v1.28.8-r0 or later
- v1.29: v1.29.4-r0 or later
- v1.30: v1.30.1-r0 or later
- The cluster can be accessed using kubectl. For details, see Accessing a Cluster Using kubectl.
Notes and Constraints
- A custom EIP for a Service can be configured only when the Service is being updated, and the Service's annotation contains kubernetes.io/elb.eip-id.
- A custom EIP must be unbound to any resources.
- After you configure a custom EIP for a load balancer, if the existing EIP bound to the load balancer was automatically created by CCE during load balancer creation and is not being used by any other resources, the existing EIP will be deleted automatically when the associated Service is deleted. However, if the existing EIP was manually created, it will be unbound from the load balancer when you delete the Service, and you will need to manually delete the EIP.
Using kubectl
- Use kubectl to access the cluster. For details, see Accessing a Cluster Using kubectl.
- Automatically create a load balancer with an EIP bound when creating a Service. For details, see Using kubectl to Create a Service (Automatically Creating a Load Balancer).
An example YAML file of a Service created using a dedicated load balancer is as follows:
apiVersion: v1kind: Servicemetadata:annotations:kubernetes.io/elb.autocreate: '{"type":"public","bandwidth_name":"aaaaa","bandwidth_chargemode":"bandwidth","bandwidth_size":5,"bandwidth_sharetype":"PER","eip_type":"5_g-vm","name":"xxx","available_zone":["xxx"],"elb_virsubnet_ids":["fc0c61cd-c987-49c4-99a4-b7d816b57581"],"l7_flavor_name":"","l4_flavor_name":"L4_flavor.elb.pro.max","vip_subnet_cidr_id":"cf35b03f-c6ca-4f75-aa70-e2166cb1f800"}'kubernetes.io/elb.eip-id: 8560972c-2cc5-4699-94d6-e46f146eb73d # ID of the EIP automatically assigned during load balancer creationkubernetes.io/elb.class: performancekubernetes.io/elb.id: 0e78a84a-7deb-4747-aeb6-09b6a820b001labels:app: test-svcversion: v1name: test-eipnamespace: defaultspec:allocateLoadBalancerNodePorts: trueclusterIP: 10.247.93.235clusterIPs:- 10.247.93.235externalTrafficPolicy: ClusterinternalTrafficPolicy: ClusteripFamilies:- IPv4ipFamilyPolicy: SingleStackloadBalancerIP: *.*.*.*ports:- name: cce-service-0nodePort: 31354port: 80protocol: TCPtargetPort: 80selector:app: test-svcversion: v1sessionAffinity: Nonetype: LoadBalancerstatus:loadBalancer:ingress:- ip: *.*.*.*- ip: 192.168.0.15 - Modify the Service configurations and add the kubernetes.io/elb.custom-eip-id annotation.apiVersion: v1kind: Servicemetadata:annotations:kubernetes.io/elb.autocreate: '{"type":"public","bandwidth_name":"aaaaa","bandwidth_chargemode":"bandwidth","bandwidth_size":5,"bandwidth_sharetype":"PER","eip_type":"5_g-vm","name":"xxx","available_zone":["xxx"],"elb_virsubnet_ids":["fc0c61cd-c987-49c4-99a4-b7d816b57581"],"l7_flavor_name":"","l4_flavor_name":"L4_flavor.elb.pro.max","vip_subnet_cidr_id":"cf35b03f-c6ca-4f75-aa70-e2166cb1f800"}'kubernetes.io/elb.eip-id: 8560972c-2cc5-4699-94d6-e46f146eb73d # ID of the EIP automatically assigned during load balancer creationkubernetes.io/elb.custom-eip-id: 88c197a1-cb85-4b38-b672-1d60dc5d00db # ID of the custom EIPkubernetes.io/elb.class: performancekubernetes.io/elb.id: 0e78a84a-7deb-4747-aeb6-09b6a820b001labels:app: test-svcversion: v1name: test-eipnamespace: defaultspec:allocateLoadBalancerNodePorts: trueclusterIP: 10.247.93.235clusterIPs:- 10.247.93.235externalTrafficPolicy: ClusterinternalTrafficPolicy: ClusteripFamilies:- IPv4ipFamilyPolicy: SingleStackloadBalancerIP: *.*.*.*ports:- name: cce-service-0nodePort: 31354port: 80protocol: TCPtargetPort: 80selector:app: test-svcversion: v1sessionAffinity: Nonetype: LoadBalancerstatus:loadBalancer:ingress:- ip: *.*.*.*- ip: 192.168.0.15
Table 1 Key parameters Parameter
Type
Description
kubernetes.io/elb.custom-eip-id
String
ID of the custom EIP, which can be seen on the EIP console
The EIP must be bindable.
- After the Service is updated, check the Service again.apiVersion: v1kind: Servicemetadata:annotations:kubernetes.io/elb.autocreate: '{"type":"public","bandwidth_name":"aaaaa","bandwidth_chargemode":"bandwidth","bandwidth_size":5,"bandwidth_sharetype":"PER","eip_type":"5_g-vm","name":"xxx","available_zone":["xxx"],"elb_virsubnet_ids":["fc0c61cd-c987-49c4-99a4-b7d816b57581"],"l7_flavor_name":"","l4_flavor_name":"L4_flavor.elb.pro.max","vip_subnet_cidr_id":"cf35b03f-c6ca-4f75-aa70-e2166cb1f800"}'kubernetes.io/elb.eip-id: 8560972c-2cc5-4699-94d6-e46f146eb73d # ID of the EIP automatically assigned during load balancer creationkubernetes.io/elb.custom-eip-id: 88c197a1-cb85-4b38-b672-1d60dc5d00db # ID of the custom EIPkubernetes.io/elb.custom-eip-status: '{"id":"88c197a1-cb85-4b38-b672-1d60dc5d00db","public_ip_address":"2.2.2.2"}' # After the custom EIP is configured, record the EIP and its ID.kubernetes.io/elb.class: performancekubernetes.io/elb.id: 0e78a84a-7deb-4747-aeb6-09b6a820b001labels:app: test-svcversion: v1name: test-eipnamespace: defaultspec:allocateLoadBalancerNodePorts: trueclusterIP: 10.247.93.235clusterIPs:- 10.247.93.235externalTrafficPolicy: ClusterinternalTrafficPolicy: ClusteripFamilies:- IPv4ipFamilyPolicy: SingleStackloadBalancerIP: 2.2.2.2ports:- name: cce-service-0nodePort: 31354port: 80protocol: TCPtargetPort: 80selector:app: test-svcversion: v1sessionAffinity: Nonetype: LoadBalancerstatus:loadBalancer:ingress:- ip: 2.2.2.2- ip: 192.168.0.15
Parent topic: LoadBalancer
- Prerequisites
- Notes and Constraints
- Using kubectl