When you use a Network Load Balancer (NLB) for a Kubernetes Service, you can use annotations in the YAML file to enable additional load balancing features. For example, you can specify the NLB network type, enable configuration read-only mode, or configure mutual authentication. This topic describes common NLB configuration operations using annotations in Service YAML files. These operations are grouped into three resource categories: NLB, listeners, and vServer groups.
Index
Category | Feature category | Configuration link |
Create a load balancer | ||
Instance configuration | ||
Security configuration | ||
Create a listener | ||
Listener configuration | ||
Security configuration | ||
Server configuration | ||
Important notes
Your ACK cluster version must be 1.24 or later, and your Cloud Controller Manager (CCM) version must be 2.5.0 or later. To upgrade your cluster, see Manually upgrade a cluster. To upgrade components, see Manage components.
In the Service specification, set
spec.loadBalancerClasstoalibabacloud.com/nlb. If you do not specify this field, Alibaba Cloud creates a Classic Load Balancer (CLB) instance by default. For more information, see Classic Load Balancer (CLB).You cannot change
spec.loadBalancerClassafter you create a Service. You cannot convert between CLB and NLB resources.You cannot manage NLBs in the Container Service console. Use the
kubectlcommand instead.
Typical NLB operations
Create an Internet-facing NLB
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps
Description | Supported CCM versions |
Specify the zone, private IP, and EIP information for the NLB, in the following format:
| Zone and vSwitch ID: Version 2.5.0 or later Private IP address and EIP: Version 2.12.1 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerCreate an internal NLB
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type
Description | Supported CCM versions |
Specify that the NLB is internal. You can change this annotation value to switch between Internet-facing and internal NLBs. Valid values:
Default value: To view supported regions and zones, go to the NLB console. You must specify at least two zones. Separate zones with commas. Example: | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSpecify a private IP address for the load balancer
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps
Description | Supported CCM versions |
Specify the zone, private IP, and EIP for the NLB in the following format:
|
|
apiVersion: v1
kind: Service
metadata:
annotations:
# For example, cn-hangzhou-k:vsw-i123456:10.1.0.1,cn-hangzhou-j:vsw-j654321:10.2.0.1
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A}:${private-ipv4-A},${zone-B}:${vsw-B}:${private-ipv4-B}"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSpecify an EIP ID for the load balancer
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps
Description | Supported CCM versions |
Specify the zone, private IP, and EIP information for the NLB in the following format:
| Zone and vSwitch ID: Version 2.5.0 or later Private IP address and EIP: Version 2.12.1 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
# Leave the private IP address blank if not needed.
# For example, cn-hangzhou-k:vsw-i123456::eip-12345,cn-hangzhou-j:vsw-j654321::eip-54321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A}::${eip-A},${zone-B}:${vsw-B}::${eip-B}"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSpecify a load balancer name
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-name
Description | Supported CCM versions |
Specify a name for the load balancer instance. The name must be 2 to 128 characters in length. It must start with a letter or Chinese character. It can contain letters, digits, periods (.), underscores (_), and hyphens (-). | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-name: "${your-nlb-name}" # NLB name.
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSpecify a resource group for the load balancer
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-resource-group-id
Description | Supported CCM versions |
Specify a resource group for the load balancer. After you specify the resource group ID, you cannot modify it. To query the resource group ID, go to the Alibaba Cloud Resource Management console. | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-resource-group-id: "${your-resource-group-id}" # Resource group ID.
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerCreate a dual-stack NLB
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version
Description | Supported CCM versions |
Specifies the protocol version of the Network Load Balancer (NLB). The IP address type cannot be modified after the NLB is created. To use this feature, the kube-proxy proxy mode of the cluster must be IPVS. Valid values:
Default value: | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version: "DualStack"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerAdd tags to the load balancer
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-additional-resource-tags
Description | Supported CCM versions |
Add custom tags. Separate multiple tags with commas (,). Example: Important If you add this annotation to a Service, any manual tag changes made in the console for the corresponding load balancer instance may be overwritten. | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-additional-resource-tags: "Key1=Value1,Key2=Value2"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerUse an existing load balancer
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id | Specify the ID of an existing load balancer. | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners | Specify whether to synchronize listener configurations based on the Service. Valid values:
Default value: |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: "${your-nlb-id}" # NLB ID.
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerAttach an Internet Shared Bandwidth package
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-bandwidth-package-id
Description | Supported CCM versions |
Specify the ID of an Internet Shared Bandwidth package. To query the ID, go to the VPC console. | Version 2.9.1 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-bandwidth-package-id: "cbwp-xxxxxxxxxx"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerEnable cross-zone forwarding
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cross-zone-enabled
Description | Supported CCM versions |
Enable or disable cross-zone forwarding. Valid values:
Default value: | Version 2.13.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cross-zone-enabled: "off"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSpecify the IPv6 Public or Private Network Type
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version | Specifies the protocol version for the NLB. You cannot change the IP type after you create the NLB. The kube-proxy proxy mode for the cluster must be IPVS. Valid values:
Default value: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ipv6-address-type | Specify the IPv6 network type for the NLB. Valid values:
Default value: Note To enable Internet-facing IPv6, your VPC must contain an IPv6 gateway. For more information, see Create and manage an IPv6 gateway. | Version 2.9.1 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version: "DualStack"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ipv6-address-type: internet # Set the IPv6 network type to Internet-facing.
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerRetain automatically created load balancer instances when deleting a Service
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-lb-on-delete
Description | Supported CCM versions |
When you delete a LoadBalancer-type Service, retain the NLB instance created by the Service. Remove the When this feature is enabled, a Warning event of type Valid values:
Important Delete the Service instead of changing its type. Otherwise, the Service might be incorrectly re-associated with a previously retained NLB. | Version 2.10.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-lb-on-delete: "true"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerTypical listener operations
Set a security group for the listener
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-security-group-ids
Description | Supported CCM versions |
Specify one or more security groups for the listener. Separate multiple values with commas (,). Example: | Version 2.6.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-security-group-ids: "sg-aaaaa,sg-bbbbb" # Separate multiple security groups with commas.
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerConfigure Both TCP and UDP Protocols for a Listener
Description | Supported CCM versions |
Your Kubernetes cluster version must be 1.24 or later. To upgrade your cluster, see Upgrade the Kubernetes version of an ACK cluster. | Not applicable |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: udp
port: 80
protocol: UDP
targetPort: 81
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerCreate a TCP listener
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerCreate a UDP listener
If you create a UDP listener without specifying a health check, the system enables a TCP health check for the vServer group by default. When you use a UDP listener, we recommend that you explicitly configure a UDP health check or disable health checks.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: udp
port: 80
protocol: UDP
targetPort: 80
selector:
app: nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerCreate a TCP/SSL listener
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port | Specify the protocol for the listener. Separate multiple values with commas (,). Example: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id | Specify the server certificate ID. To create and view a certificate, go to the Certificate Management Service console, and then click SSL Certificates. The following figure shows an example.
|
Currently, TCP/SSL listeners do not support attaching to server groups that have the client address preservation feature enabled—that is, you cannot configure both the service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "tcpssl:${port}" and service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-client-ip: "on" annotations simultaneously. To obtain the originating IP address through NLB, see Obtaining the Originating IP Address Through NLB.
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "tcpssl:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${CertIdentifier}"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerConfigure a listener port range
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-listener-port-range
Description | Supported CCM versions |
This annotation is supported only when you use the Terway network plug-in. Configure a port range for full-port forwarding to listen on specific ports and forward traffic to the corresponding ports on backend servers. Format: The | Version 2.11.4 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
# Configure listeners for port ranges 80-100 and 400-500.
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-listener-port-range: "80-100:80,400-500:443"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
# targetPort is the health check port on the backend server. It must be an integer.
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerEnable mutual authentication
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port | Specify the protocol for the listener. Separate multiple values with commas (,). Example: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id | Specify the server certificate ID. To create and view a certificate, go to the Certificate Management Service console, and then click SSL Certificates. The following figure shows an example.
| |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cacert-id | Specify the CA certificate ID. To view the ID, go to the Certificate Management Service console, and then click PCA Certificates.
| |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cacert | Enable or disable mutual authentication. Valid values:
Default value: |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "tcpssl:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${CertIdentifier}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cacert-id: "${your-cacert-id}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cacert: "on"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSet the TLS security policy
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port | Specify the protocol for the listener. Separate multiple values with commas (,). Example: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id | Specify the server certificate ID. To create and view a certificate, go to the Certificate Management Service console, and then click SSL Certificates. The following figure shows an example.
| |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-tls-cipher-policy | Specify the security policy ID. Supported policies include system-defined and custom policies. Valid values:
Default value: |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "tcpssl:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${CertIdentifier}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-tls-cipher-policy: "tls_cipher_policy_1_0"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerEnable Proxy Protocol
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-proxy-protocol
Description | Supported CCM versions |
Enable or disable Proxy Protocol to carry the source IP address of clients to backend servers. Valid values:
Default value: Important Before enabling Proxy Protocol, verify that your backend services support Proxy Protocol v2. Otherwise, requests fail. | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-proxy-protocol: "on"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerCarry additional information with Proxy Protocol
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-proxy-protocol | Enable or disable Proxy Protocol to carry the source IP address of clients to backend servers. Valid values:
Default value: Important Before enabling Proxy Protocol, verify that your backend services support Proxy Protocol v2. Otherwise, requests fail. | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ppv2-pvl-vpc-id-enabled | Enable or disable carrying the VPC ID to backend servers using Proxy Protocol. Valid values:
Default value: | Version 2.9.1 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ppv2-pvl-ep-id-enabled | Enable or disable carrying the PrivateLink endpoint ID to backend servers using Proxy Protocol. Valid values:
Default value: | Version 2.9.1 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ppv2-pvl-eps-id-enabled | Enable or disable carrying the PrivateLink endpoint service ID to backend servers using Proxy Protocol. Valid values:
Default value: | Version 2.9.1 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-proxy-protocol: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ppv2-pvl-ep-id-enabled: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ppv2-pvl-eps-id-enabled: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ppv2-pvl-vpc-id-enabled: "on"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSet the new connection rate limit per second for a listener
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cps
Description | Supported CCM versions |
Set the maximum number of new connections per second for the NLB instance. Valid values: 0 to 1000000. A value of 0 means no limit. | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cps: "100"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSet the idle timeout for listener connections
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-idle-timeout
Description | Supported CCM versions |
Set the idle timeout for connections. Unit: seconds. Valid values: 10 to 900. Default value: 900 | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-idle-timeout: "60"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSet the ALPN policy
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port | Specify the protocol for the listener. Separate multiple values with commas (,). Example: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id | Specify the server certificate ID. To create and view a certificate, go to the Certificate Management Service console, and then click SSL Certificates. The following figure shows an example.
| |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-alpn | Enable or disable ALPN. Valid values:
Default value: | Version 2.10.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-alpn-policy | Specify the ALPN policy. Valid values:
For more valid values, see the |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "tcpssl:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${CertIdentifier}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-alpn: "on"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-alpn-policy: "HTTP1Only"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerConfigure extended certificates
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port | Specify the protocol for the listener. Separate multiple values with commas (,). Example: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id | Specify the server certificate ID. To create and view a certificate, go to the Certificate Management Service console, and then click SSL Certificates. The following figure shows an example.
| |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-additional-cert-ids | Specify one or more extended certificate IDs. Separate multiple IDs with commas (,). To create and view certificates, go to the Certificate Management Service console, and then click SSL Certificates. For example, see the following graph:
|
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "tcpssl:443"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cert-id: "${CertIdentifier}"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-additional-cert-ids: "${CertIdentifier-1},${CertIdentifier-2}" # Separate multiple extended certificates with commas.
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerTypical vServer group operations
Set the scheduling algorithm
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-scheduler
Description | Supported CCM versions |
Specify the scheduling algorithm. Valid values:
Default value: For more valid values, see the | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-scheduler: "sch"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerEnable connection draining
Annotation: Multiple annotations, as shown in the following table.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-connection-drain | Enable or disable connection draining. When enabled, the following actions occur if a backend server is removed or fails a health check:
Default value: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-connection-drain-timeout | Set the connection draining timeout.
|
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
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:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerPreserve client IP addresses
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-client-ip
Description | Supported CCM versions |
Enable or disable client IP address preservation. Valid values:
Default value: | Version 2.5.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-client-ip: "on"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerConfigure TCP health checks
Annotation: Multiple annotations, as shown in the following table. To configure TCP health checks, you must specify all these annotations. TCP health checks are enabled by default.
Annotation | Description |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-flag | Enable or disable health checks. Valid values:
Default value: |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-type | Specify the health check protocol. Valid values:
Default value: |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-connect-port | Specify the server port for health checks. Valid values: 0 to 65535. Default value: 0, which means use the server port. |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-connect-timeout | Set the maximum timeout for health check responses. Unit: seconds. Valid values: 1 to 300. Default value: 5 |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-healthy-threshold | Set the number of consecutive successful health checks required to mark a server as healthy. Valid values: 2 to 10. Default value: 2 |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-unhealthy-threshold | Set the number of consecutive failed health checks required to mark a server as unhealthy. Valid values: 2 to 10. Default value: 2 |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-interval | Set the interval between health checks. Unit: seconds. Valid values: 1 to 50. Default value: 10 |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-flag: "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: "5"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerConfigure HTTP health checks
Annotation: Multiple annotations, as shown in the following table. To configure HTTP health checks, you must specify all these annotations. TCP health checks are enabled by default.
Annotation | Description | Supported CCM versions |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-flag | Enable or disable health checks. Valid values:
Default value: | Version 2.5.0 or later |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-type | Specify the health check protocol. Valid values:
Default value: | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-uri | Specify the health check path. Length: 1 to 80 characters. Use only letters, digits, and hyphens (-). Must start with a forward slash (/). For more information, see CreateServerGroup. Note This parameter takes effect only when | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-domain | Specify the domain name for health checks. Valid values:
Note This parameter takes effect only when | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-connect-port | Specify the server port for health checks. Valid values: 0 to 65535. Default value: 0, which means use the server port. | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-connect-timeout | Set the maximum timeout for health check responses. Unit: seconds. Valid values: 1 to 300. Default value: 5 | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-healthy-threshold | Set the number of consecutive successful health checks required to mark a server as healthy. Valid values: 2 to 10. Default value: 2 | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-unhealthy-threshold | Set the number of consecutive failed health checks required to mark a server as unhealthy. Valid values: 2 to 10. Default value: 2 | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-interval | Set the interval between health checks. Unit: seconds. Valid values: 1 to 50. Default value: 10 | |
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-method | Specify the health check method. Valid values:
Note This parameter takes effect only when |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
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-health-check-domain: "www.test.com"
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-connect-timeout: "10"
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-interval: "5"
# Optional annotation to set the health check method.
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-health-check-method: "head"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerSet the vServer group type
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-server-group-type
Description | Supported CCM versions |
Specify the vServer group type. Valid values:
Default value: For more information about NLB vServer group types, see NLB vServer groups. | Version 2.8.0 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-server-group-type: "Ip"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancerReuse an existing vServer group
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-vgroup-port
Reuse an existing vServer group. This annotation applies only when you reuse an existing NLB. For usage examples, see Deploy services across clusters by reusing an existing load balancer.
Set the traffic weight for the Service
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-weight
In scenarios where multiple Services reuse the same NLB, use this annotation to set the traffic weight for the current Service. This annotation applies only when you reuse an existing vServer group. For usage examples, see Deploy services across clusters by reusing an existing load balancer.
Ignore backend server weight updates
Annotation: service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ignore-weight-update
Description | Supported CCM versions |
Skip updating backend server weights in the vServer group during Service synchronization. Use this annotation when you manually manage backend server weights outside of CCM. Valid values:
Default value: | Version 2.11.1 or later |
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: "${zone-A}:${vsw-A},${zone-B}:${vsw-B}" # For example, cn-hangzhou-k:vsw-i123456,cn-hangzhou-j:vsw-j654321
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ignore-weight-update: "on"
name: nginx
namespace: default
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: nginx
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancer
