Updated on 2024-09-24 GMT+08:00

Service Affinity

If node affinity is configured, the load balancer may fail to be accessed in some scenarios. For details, see Why the ELB Address Cannot Be used to Access Workloads in a Cluster?

  1. Log in to the CCE Console console and click the cluster name to access the cluster console. In the navigation pane, choose Services & Ingresses > Services. Then, locate the Service you want to operate and choose More > Edit YAML in the Operation column.
  2. Configure the following parameters in YAML:

    spec:
      type: LoadBalancer
      externalTrafficPolicy: Local
      allocateLoadBalancerNodePorts: true

    You can also choose More > Update in the Operation column of the Service to configure the parameters.

    Parameter description

    Parameter

    Description

    Service Affinity (externalTrafficPolicy)

    The options are as follows:

    Cluster-level (Cluster in YAML): Requests are forwarded within the cluster. The backend workload can be accessed from any node IP address and service port. However, routing hops bring in performance loss, and the client source IP address cannot be obtained.

    Node-level (Local in YAML): Requests are forwarded only to the pod on the local node. If there is no pod, the requests will be suspended.

    If dedicated load balancers are deployed for CCE Turbo clusters, passthrough networking is supported to reduce the network latency and ensure zero performance loss. In this case, the value must be Cluster-level (Cluster in YAML).

    In other scenarios, requests are transmitted through a load balancer to a node and then forwarded to the target pod through the Service. In this case, the recommended value is Node-level (Local in YAML). The traffic is finally forwarded to the pod on the local node instead of being balanced to pods on other nodes. This avoids request exceptions caused by cross-node network faults.