All Products
Search
Document Center

Container Compute Service:Use AlbConfigs to configure ALB listeners

Last Updated:Mar 26, 2026

Configure listeners for an Application Load Balancer (ALB) instance by setting the listeners field in an AlbConfig. This topic covers how to create, update, and delete listeners, and how to configure certificates, TLS policies, timeouts, compression, header forwarding, and network ACLs.

Prerequisites

Before you begin, ensure that you have:

Listener parameters at a glance

All listener parameters are set under spec.listeners[] in the AlbConfig. The following table lists the available fields.

ParameterTypeDefaultValid valuesDescription
portintegerListener port. Together with protocol, uniquely identifies a listener.
protocolstringHTTP, HTTPS, QUICListener protocol. Together with port, uniquely identifies a listener.
certificates[].CertificateIdstringCertificate IDThe certificate to bind to an HTTPS listener. The first entry is used as the default certificate.
certificates[].IsDefaultbooleantrue, falseWhether the certificate is the default certificate.
caEnabledbooleanfalsetrue, falseWhether to enable CA certificate authentication for the HTTPS listener.
securityPolicyIdstringPolicy IDTLS security policy to apply to an HTTPS listener.
requestTimeoutinteger601–180Connection timeout in seconds. ALB returns HTTP 504 if the backend does not respond within this period.
gzipEnabledbooleantrue, falseWhether to enable data compression (Brotli and Gzip).
xForwardedForConfig.XForwardedForEnabledbooleantrue, falseWhether to include the client IP in the X-Forwarded-For header. HTTP and HTTPS only.
xForwardedForConfig.XForwardedForProtoEnabledbooleantrue, falseWhether to include the ALB listening protocol in the X-Forwarded-For header. HTTP and HTTPS only.
xForwardedForConfig.XForwardedForSLBIdEnabledbooleantrue, falseWhether to include the ALB instance ID in the X-Forwarded-For header. HTTP and HTTPS only.
xForwardedForConfig.XForwardedForSLBPortEnabledbooleantrue, falseWhether to include the ALB listening port in the X-Forwarded-For header. HTTP and HTTPS only.
xForwardedForConfig.XForwardedForClientSourceIpsEnabledbooleantrue, falseWhether to retrieve the real client IP from the X-Forwarded-For header based on trusted proxies. Requires XForwardedForClientSourceIpsTrusted. HTTP and HTTPS only.
xForwardedForConfig.XForwardedForClientSourceIpsTrustedstringIP addresses or CIDR blocks, semicolon-separatedTrusted proxy IP addresses. ALB traverses the X-Forwarded-For header from right to left; the first IP not in this list is treated as the client IP. Takes effect only when XForwardedForClientSourceIpsEnabled is true.
aclConfig.aclTypestringWhite, BlackACL type: White (whitelist) or Black (blacklist).
aclConfig.aclEntries[]string arrayCIDR blocksIP addresses or CIDR blocks to allow or deny.

How listener updates work

The listeners field is an array. When you apply a new AlbConfig, each entry is matched against the live configuration and the last-applied-configuration annotation to determine what to add, retain, or delete.

Key concepts

  • Object configuration file: the YAML file you apply with kubectl apply or kubectl edit.

  • Live object configuration file: the AlbConfig currently active in the cluster.

  • `last-applied-configuration`: a Kubernetes annotation that records the content of the last applied configuration. It is not updated in real time when the configuration changes.

Update rules

New configLive configlast-applied-configurationResult
YesYes— (irrelevant)Listener is retained.
YesNo— (irrelevant)Listener is added.
No— (irrelevant)YesListener is deleted. Fields may be reset to defaults.
NoYesNoListener is retained.

Example

Given the following three states:

Object configuration file (what you are applying):

listeners:
- port: 8001
  protocol: HTTP
- port: 8003
  protocol: HTTP
- port: 8005  # Adding port 8005.
  protocol: HTTP

Live object configuration file (current cluster state):

listeners:
- port: 8001
  protocol: HTTP
- port: 8002  # Not in new config; in last-applied-configuration.
  protocol: HTTP
- port: 8003
  protocol: HTTP
- port: 8004  # Not in new config; not in last-applied-configuration.
  protocol: HTTP

`last-applied-configuration` annotation:

listeners:
- port: 8001
  protocol: HTTP
- port: 8002
  protocol: HTTP
- port: 8003
  protocol: HTTP

After applying the new configuration, the result is:

listeners:
- port: 8001
  protocol: HTTP
- port: 8003
  protocol: HTTP
- port: 8005
  protocol: HTTP
PortRule matchedResult
8001Rule 1: present in new config and live configRetained
8003Rule 1: present in new config and live configRetained
8005Rule 2: present in new config, not in live configAdded
8002Rule 3: absent from new config, present in last-applied-configurationDeleted
8004Rule 4: absent from new config, present in live config, absent from last-applied-configurationRetained

Create a listener

ALB listeners receive and forward external requests based on application-layer information. Set port and protocol to create a listener.

Warning

port and protocol are the only identifiers of a listener. Changing either field deletes the existing listener and creates a new one. Verify these values carefully before applying changes.

apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
  name: alb-demo
spec:
  listeners:
  - port: 80
    protocol: HTTP  # Valid values: HTTP, HTTPS, QUIC.
HTTP is compatible with WebSocket. No additional configuration is required.

Apply the configuration:

kubectl edit albconfig <AlbConfig_Name>

Specify certificates for an HTTPS listener

Bind a certificate to an HTTPS listener using the certificates field. ALB uses the first certificate in the list as the default certificate and switches to others when the default expires or no longer meets requirements.

If no certificate is specified, ALB does not create the HTTPS listener immediately. Instead, it waits for an Ingress to be associated with the listener and auto-discovers a certificate based on the domain name in the Ingress configuration. This delays listener creation.

For details on certificate configuration, see Configure HTTPS certificates for encrypted communication.

listeners:
- port: 443
  protocol: HTTPS
  caEnabled: false
  certificates:
  - CertificateId: 756****-cn-hangzhou  # The certificate ID.
    IsDefault: true

Configure a TLS security policy

Apply a TLS security policy to an HTTPS listener using securityPolicyId. Both custom and default TLS security policies are supported. See TLS security policies.

listeners:
- port: 443
  protocol: HTTPS
  securityPolicyId: tls_cipher_policy_1_1  # The security policy ID.

Set the connection timeout

Set requestTimeout to prevent clients from waiting indefinitely for backend responses. If the backend does not respond within the timeout period, ALB returns HTTP 504 to the client.

  • Valid values: 1–180 seconds

  • Default: 60 seconds

listeners:
- port: 80
  protocol: HTTP
  requestTimeout: 60  # Unit: seconds. Valid values: 1–180.

Enable data compression

Set gzipEnabled to reduce response payload size and improve transmission efficiency.

  • true: enables compression. Both Brotli and Gzip algorithms are used.

    • Brotli supports all file types.

    • Gzip supports: text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, application/atom+xml, application/xml, application/json.

  • false: disables compression.

listeners:
- port: 80
  protocol: HTTP
  gzipEnabled: false  # Set to true to enable compression.

Configure X-Forwarded-For headers

The xForwardedForConfig block controls what information ALB appends to the X-Forwarded-For header. HTTP and HTTPS listeners only.

Preserve the client IP

Set XForwardedForEnabled: true to include the originating client IP in the header.

listeners:
- port: 80
  protocol: HTTP
  xForwardedForConfig:
    XForwardedForEnabled: true

Include the listening protocol

Set XForwardedForProtoEnabled: true to include the ALB listening protocol in the header.

listeners:
- port: 80
  protocol: HTTP
  xForwardedForConfig:
    XForwardedForProtoEnabled: true

Include the ALB instance ID

Set XForwardedForSLBIdEnabled: true to include the ALB instance ID in the header.

listeners:
- port: 80
  protocol: HTTP
  xForwardedForConfig:
    XForwardedForSLBIdEnabled: true

Include the listening port

Set XForwardedForSLBPortEnabled: true to include the ALB listening port in the header.

listeners:
- port: 80
  protocol: HTTP
  xForwardedForConfig:
    XForwardedForSLBPortEnabled: true

Retrieve the real client IP from trusted proxies

When traffic passes through proxy servers, use XForwardedForClientSourceIpsEnabled together with XForwardedForClientSourceIpsTrusted to identify the real client IP. ALB traverses the X-Forwarded-For header from right to left; the first IP not in the trusted list is treated as the client IP, and requests from that IP are throttled.

listeners:
- port: 80
  protocol: HTTP
  xForwardedForConfig:
    XForwardedForClientSourceIpsEnabled: true  # Must be true before XForwardedForClientSourceIpsTrusted takes effect.
    XForwardedForClientSourceIpsTrusted: 192.168.x.x;192.168.x.x/16  # Semicolon-separated IP addresses or CIDR blocks.

Configure network ACLs

Use aclConfig to allow or deny access from specific IP addresses or CIDR blocks. See Configure an ACL to enable access control.

listeners:
- port: 80
  protocol: HTTPS
  aclConfig:
    aclType: White  # White (whitelist) or Black (blacklist).
    aclEntries:
    - 127.0.0.1/32  # IP address or CIDR block to allow or deny.

Delete a listener

To delete a listener, remove its entry from spec.listeners in the AlbConfig.

Important

Disassociate all Ingresses from the listener before deleting it. Failing to do so causes the deletion to fail with an error.

# Before deletion:
listeners:
- port: 8001
  protocol: HTTP
- port: 8002
  protocol: HTTP

# After deletion (port 8002 removed):
listeners:
- port: 8001
  protocol: HTTP

What's next