All Products
Search
Document Center

Container Service for Kubernetes:Considerations for configuring a LoadBalancer Service

Last Updated:Apr 29, 2024

When you specify Type=LoadBalancer for a Service, the Cloud Controller Manager (CCM) creates and configures Server Load Balancer (SLB) resources for the Service, including SLB instances, listeners, and backend server groups. This topic describes the considerations for configuring a LoadBalancer Service and the policies that are used by the CCM to update SLB resources.

Policies used by the CCM to update SLB resources

Container Service for Kubernetes (ACK) allows you to specify an existing SLB instance for a Service. You can also use the CCM to automatically create an SLB instance for the Service. The two methods use different policies to update SLB resources. The following table describes the differences.

Resource object

Existing SLB instance

SLB instance created and managed by the CCM

SLB

Use the following annotation to specify an existing SLB instance for a Service: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id.

  • The CCM uses the specified SLB instance to enable load balancing. You can use other annotations to configure the SLB instance. The CCM automatically creates vServer groups for the instance.

  • If the Service is deleted, the CCM does not delete the existing SLB instance that is specified in the annotation.

  • The CCM automatically creates, configures, and manages SLB resources based on the Service configuration, including the SLB instance, listeners, and vServer groups.

  • If the Service is deleted, the CCM deletes the created SLB instance.

Listener

Use the following annotation to configure listeners: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners.

  • If you set the annotation to false, the CCM does not configure or manage listeners for the SLB instance.

  • If you set the annotation to true, the CCM configures and manages listeners for the SLB instance based on the Service configuration. If the SLB instance has existing listeners, the CCM creates new listeners to replace the existing ones.

The CCM configures listeners for the SLB instance based on the Service configuration.

Backend server group

When the endpoints of a Service change or the cluster nodes change, the CCM automatically updates the vServer groups of the SLB instance created for the Service.

  • If the cluster uses the Terway network plug-in, the CCM associates pod IP addresses instead of Elastic Compute Service (ECS) nodes with SLB instances by default.

  • If the cluster uses the Flannel network plug-in, the policies for updating backend server groups vary based on the mode of the Service.

    • If spec.externalTrafficPolicy = Cluster is specified for a Service, the CCM adds all cluster nodes to the SLB instance by default. If node labels are specified in the Service configuration, the CCM adds only cluster nodes that have the specified labels to the SLB instance.

      Important

      The number of SLB instances to which an ECS instance can be added is limited. If a Service is in Cluster mode, the quota is consumed at a high rate. When the quota is used up, Service reconciliation fails. To fix this issue, set the Local mode for the Service.

    • If spec.externalTrafficPolicy = Local is specified for a Service, the CCM adds only the nodes where the backend pods of the Service are deployed to the SLB instance. This can reduce the consumption rate of SLB quotas. In addition, source IP addresses can also be preserved in Layer 4 load balancing.

  • If the cluster uses the Flannel network plug-in, the CCM does not add master nodes to the SLB instances used by the cluster.

  • If the cluster uses the Flannel network plug-in, the CCM does not remove a node after you run the kubectl drain command on the node. In addition, the CCM does not remove a node after you run the kubectl cordon command to mark the node as unschedulable. To remove such a node, set the service.beta.kubernetes.io/alibaba-cloud-loadbalancer-remove-unscheduled-backend annotation to on.

Usage notes

  • Before you reuse an existing SLB instance, check whether the instance meets the following requirements:

    • The SLB instance that you want to reuse is created in the SLB console. You cannot reuse an SLB instance that is created by the CCM.

    • To reuse an internal-facing SLB instance for a cluster, the SLB instance and the cluster must be deployed in the same virtual private cloud (VPC).

  • Considerations for using the CCM to configure an SLB instance

    • The CCM configures SLB instances only for LoadBalancer Services.

      Important

      If you change the of a Service from Type=LoadBalancer to Type!=LoadBalancer, the CCM automatically deletes the configurations related to the SLB instance created for Service. As a result, you cannot use the SLB instance to access the Service.

    • When specific conditions are met, the CCM uses a declarative API to automatically update the configuration of an SLB instance based on the Service configuration. If you set service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners to true, the SLB configurations that you update in the SLB console may be overwritten.

      Important

      If the SLB instance is created and managed by the CCM, we recommend that you do not modify the configuration of the SLB instance in the SLB console. Otherwise, the CCM may overwrite the configuration and the Service may become unavailable.

Quotas

VPC

SLB