Configure Classic Load Balancer (CLB) instances, listeners, and backend server groups by adding annotations to the YAML file of a Kubernetes Service.
Overview
This topic describes how to use Service annotations to configure CLB instances in Container Compute Service (ACS). Annotations let you customize load balancing behavior without modifying the CLB console directly.
Before you begin:
Annotation values are case-sensitive.
Check the Cloud Controller Manager (CCM) version requirements for each annotation. For CCM updates, see Manage components. For CCM release notes, see Cloud Controller Manager.
Since September 11, 2019, the annotation prefix changed from
alicloudtoalibaba-cloud. Both prefixes are supported for backward compatibility.
Contents
CLB instance management
Create an Internet-facing CLB instance
By default, a LoadBalancer Service creates an Internet-facing CLB instance:
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerCreate an internal-facing CLB instance
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerCreate a CLB instance with specific specifications
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3+ |
| CLB specification. See CreateLoadBalancer. |
| 1.9.3+ |
If you modify specifications in the CLB console, the CCM may restore them. Use annotations for specification changes.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-instance-charge-type: "PayBySpec"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: "slb.s1.small"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerUse an existing CLB instance
Annotation | Description | Default | CCM Version |
| ID of an existing CLB instance | None | 1.9.3.81+ |
|
|
| 1.9.3.81+ |
By default, existing listeners are preserved to prevent service interruptions. Use the force-override-listeners annotation only when the listener ports are no longer in use.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: "${YOUR_LOADBALANCER_ID}"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerTo forcefully overwrite listeners:
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: "${YOUR_LOADBALANCER_ID}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerSpecify primary and secondary zones
Annotation | Description | Default | CCM Version |
| Primary zone ID | None | 1.9.3.10+ |
| Secondary zone ID | None | 1.9.3.10+ |
Zones cannot be changed after the CLB instance is created. Not all regions support primary/secondary zones.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-master-zoneid: "cn-hangzhou-k"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-slave-zoneid: "cn-hangzhou-j"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerCreate a pay-by-bandwidth CLB instance
Both annotations are required:
Annotation | Description | Default | CCM Version |
| Set to |
| 1.9.3+ |
| Maximum bandwidth (Mbps). Internet-facing only. |
| 1.9.3.10+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-charge-type: "paybybandwidth"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-bandwidth: "2"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerSpecify a vSwitch for internal CLB
Both annotations are required:
Annotation | Description | Default | CCM Version |
| Must be |
| 1.9.3+ |
| vSwitch ID (must be in same VPC as cluster) | None | 1.9.3+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-vswitch-id: "${YOUR_VSWITCH_ID}"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerSpecify an IP address for internal CLB
Annotation | Description | Default | CCM Version |
| IP address within vSwitch CIDR. IPv4 only. Cannot be changed after creation. | None | 2.7.0+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-vswitch-id: "${YOUR_VSWITCH_ID}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip: "192.168.x.x"
name: nginx
namespace: default
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
name: http
selector:
app: nginxCreate an IPv6 CLB instance
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3.220+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version: "ipv6"
name: nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancerEnable deletion protection
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3.313+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-delete-protection: "on"
name: nginx
spec:
externalTrafficPolicy: Local
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancerEnable configuration read-only mode
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3.313+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-modification-protection: "ConsoleProtection"
name: nginx
spec:
externalTrafficPolicy: Local
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancerSpecify the CLB instance name
Annotation | Description | Default | CCM Version |
| 2-128 characters: letters, digits, periods, underscores, hyphens. Must start with a letter. | None | 1.9.3.313+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-name: "your-svc-name"
name: nginx
spec:
externalTrafficPolicy: Local
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancerSpecify the resource group
Annotation | Description | Default | CCM Version |
| Resource group ID. Cannot be changed after creation. | None | 1.9.3.313+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-resource-group-id: "rg-xxxx"
name: nginx
spec:
externalTrafficPolicy: Local
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancerSpecify a hostname for a Service
Annotation | Description | Default | CCM Version |
| Domain name for the Service | None | 2.3.0+ |
| Protocol and port mapping (e.g., | None | 1.9.3+ |
This annotation changes the external IP to your service name. For TCP/UDP listeners, a loop occurs when requests from within the cluster are forwarded to the CLB IP address. You must separately purchase and configure the domain name.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "http:80"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-hostname: "${your_service_hostname}"
name: nginx-svc
namespace: default
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancerCreate a pay-by-LCU CLB instance
Annotation | Description | Default | CCM Version |
|
|
| 2.4.0+ |
You cannot specify both PayByCLCU and a CLB specification annotation.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-instance-charge-type: "PayByCLCU"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerRetain CLB instance when deleting a Service
Annotation | Description | CCM Version |
| Any non-empty value enables retention. The CLB instance and backend servers are preserved when the Service is deleted. | 2.10.0+ |
Delete the Service rather than changing its type. Otherwise, the Service will be re-associated with the original CLB instance.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-lb-on-delete: "true"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerListener configuration
TCP session persistence
Annotation | Description | Default | CCM Version |
| Session persistence timeout (0-3600 seconds). TCP listeners only. 0 disables persistence. |
| 1.9.3+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-persistence-timeout: "1800"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerConfigure an ACL
Before using these annotations, create an ACL in the CLB console.
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3.164+ |
| ACL ID | None | 1.9.3.164+ |
|
| None | 1.9.3.164+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-acl-status: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-acl-id: "${YOUR_ACL_ID}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-acl-type: "white"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerConfigure HTTP to HTTPS port forwarding
Annotation | Description | Default | CCM Version |
| Protocol-port mappings (e.g., | None | 1.9.3+ |
| Certificate ID from CLB console | None | 1.9.3.164+ |
| Forward HTTP to HTTPS (e.g., | None | 1.9.3.164+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "https:443,http:80"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${YOUR_CERT_ID}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-forward-port: "80:443"
name: nginx
namespace: default
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: 80
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerSpecify the scheduling algorithm
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-scheduler: "wrr"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerCreate listener types
UDP listener
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: UDP
targetPort: 80
selector:
run: nginx
type: LoadBalancerHTTP listener
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "http:80"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerHTTPS listener
HTTPS listeners decrypt requests and forward them as HTTP to backend pods.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "https:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${YOUR_CERT_ID}"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerTCP and UDP on the same port
Requires Kubernetes 1.24 or later.
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
spec:
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: udp
port: 80
protocol: UDP
targetPort: 81
selector:
app: nginx
sessionAffinity: None
type: LoadBalancerHealth check settings
TCP health checks
Health checks are enabled by default for TCP ports.
Annotation | Description | Default | CCM Version |
|
|
| 2.6.0+ |
|
|
| 1.9.3+ |
| Timeout (1-300 seconds) |
| 1.9.3+ |
| Consecutive successes to mark healthy (2-10) |
| 1.9.3+ |
| Consecutive failures to mark unhealthy (2-10) |
| 1.9.3+ |
| Check interval (1-50 seconds) |
| 1.9.3+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-switch: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-type: "tcp"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-connect-timeout: "8"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-healthy-threshold: "4"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-unhealthy-threshold: "4"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-interval: "3"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerHTTP health checks
Annotation | Description | Default | CCM Version |
|
|
| 1.9.3+ |
| Health check URI | None | 1.9.3+ |
| Success codes: |
| 1.9.3+ |
| Domain for health checks ( | None | 1.9.3+ |
| Timeout (1-300 seconds) | None | 1.9.3+ |
|
| None | 2.3.0+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-flag: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-type: "http"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-uri: "/test/index.html"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-healthy-threshold: "4"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-unhealthy-threshold: "4"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-timeout: "10"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-interval: "3"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "http:80"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerDisable health checks
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-switch: "off"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerAdvanced listener options
Connection draining
TCP and UDP listeners only.
Annotation | Description | Default | CCM Version |
|
| None | 2.0.1+ |
| Timeout (10-900 seconds) | None | 2.0.1+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-connection-drain: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-connection-drain-timeout: "30"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerAdditional request headers
HTTP and HTTPS listeners only.
Annotation | Description | Default | CCM Version |
| Add |
| 2.1.0+ |
| Add |
| 2.9.1+ |
| Add |
| 2.9.1+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "http:80"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-xforwardedfor-proto: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-xforwardedfor-slbport: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-xforwardedfor-clientsrcport: "on"
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerTimeout settings
Annotation | Description | Listeners | Default | CCM Version |
| Idle connection timeout (1-60 seconds) | HTTP, HTTPS |
| 2.1.0+ |
| Request timeout (1-180 seconds) | HTTP, HTTPS |
| 2.3.0+ |
| Connection timeout (10-900 seconds) | TCP | None | 2.3.0+ |
Disable HTTP/2
HTTPS listeners only.
Annotation | Description | Default | CCM Version |
|
|
| 2.1.0+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "https:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${YOUR_CERT_ID}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-http2-enabled: "off"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerTLS security policies
HTTPS listeners only.
Annotation | Description | Default | CCM Version |
| TLS policy: |
| 2.4.0+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "https:443,http:80"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${YOUR_CERT_ID}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-tls-cipher-policy: "tls_cipher_policy_1_2"
name: nginx
namespace: default
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: 443
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: LoadBalancerProxy protocol
TCP and UDP listeners only.
Annotation | Description | Default | CCM Version |
|
|
| 2.6.0+ |
Enabling proxy protocol may cause service interruptions. Stop and update your applications before enabling.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-proxy-protocol: "on"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerSkip backend server weight updates
Annotation | Description | CCM Version |
|
| 2.11.1+ |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ignore-weight-update: "on"
name: nginx
namespace: default
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
run: nginx
type: LoadBalancerReferences
For more information about the considerations for configuring a LoadBalancer Service and the policies that are used by the CCM to update CLB resources, see Considerations for configuring a LoadBalancer Service.
For more information about how to troubleshoot ACS Services issues, such as the annotations of a Service do not take effect, see Service FAQ.