An AlbConfig is a Custom Resource Definition (CRD) provided by the ALB Ingress Controller. The ALB Ingress Controller uses an AlbConfig to configure ALB instances and listeners. This topic describes how to create, modify, and update an AlbConfig, and how to enable Log Service.
Prerequisites
You have installed the ALB Ingress Controller.
You have created two VSwitches in different availability zones within your cluster's VPC. Create and manage VSwitches.
Usage notes
We recommend that you use the
kubectl editcommand to directly modify or update resource configurations. If you must use thekubectl applycommand to modify or update resources, run thekubectl diffcommand to preview the changes before you run thekubectl applycommand. Make sure that the changes are as expected, and then run thekubectl applycommand to apply the changes to the Kubernetes cluster.Earlier versions of the Nginx Ingress Controller do not recognize the
spec.ingressClassNamefield in Ingress resources. If both Nginx Ingress and ALB Ingress controllers are running in the same cluster, an older Nginx Ingress Controller may interfere with or overwrite the ALB Ingress configuration. To prevent this issue, update the Nginx Ingress Controller to the latest version, or use an annotation to specify the ingressClass for the ALB Ingress. For more information, see Advanced features of ALB Ingresses.
Create an AlbConfig
An AlbConfig corresponds to a single ALB instance but can be associated with multiple Ingresses. To use multiple ALB instances, you can create multiple AlbConfigs. The following steps describe how to create an AlbConfig.
Create a file named alb-test.yaml and copy the following content into it.
apiVersion: alibabacloud.com/v1 kind: AlbConfig metadata: name: alb-demo spec: config: name: alb-test addressAllocatedMode: Dynamic # Dynamic or Fixed. Specifies the IP address mode for the ALB instance. addressType: Internet zoneMappings: # For high availability, select vSwitches in at least two different zones. - vSwitchId: vsw-uf6ccg2a9g71hx8go**** # Replace with the actual vSwitch ID (Zone 1). - vSwitchId: vsw-uf6nun9tql5t8nh15**** # Replace with the actual vSwitch ID (Zone 2, must be different from Zone 1). listeners: - port: 80 protocol: HTTPParameter
Description
spec.config.name
(Optional) The name of the ALB instance.
spec.config.addressType
(Required) The address type of the load balancer. Valid values:
Internet (default): The load balancer has a public IP address. The DNS record is resolved to the public IP address, making the load balancer accessible over the internet.
Intranet: The load balancer has only a private IP address. The DNS record is resolved to the private IP address, making the load balancer accessible only from within the VPC where it is deployed.
spec.config.zoneMappings
(Required) Specifies the vSwitch IDs for the ALB Ingress. In multi-zone regions, you must specify the IDs of vSwitches in at least two different zones. In single-zone regions, one vSwitch ID is sufficient. The vSwitches must be in the same VPC as the cluster and in zones that support ALB. For more information about the regions and zones supported by ALB Ingress, see Regions and zones supported by ALB.
ImportantYou cannot update the address type or zones of an ALB instance. The
addressTypeandzoneMappingsparameters take effect only when you create an AlbConfig and cannot be updated afterward.spec.config.addressAllocatedMode(Optional) In AlbConfig, you can specify the IP mode for the ALB instance by setting the addressAllocatedMode parameter. The valid values are:
Dynamic: the dynamic IP mode.
Fixed: the fixed IP mode.
When you install the ALB Ingress Controller add-on for a cluster, the system creates an AlbConfig by default. All configuration parameters except for
vSwitchIdwill be created with the default settings.Run the following command to create the AlbConfig.
kubectl apply -f alb-test.yamlExpected output:
albconfig.alibabacloud.com/alb-demo createdRun the following command to view the AlbConfig.
kubectl -n kube-system get AlbConfigExpected output:
NAME ALBID DNSNAME PORT&PROTOCOL CERTID AGE alb-demo alb-****** alb-******.<regionID>.alb.aliyuncs.com 443/HTTPS 11055487-cn-<regionID> 2d
Update an AlbConfig
In Kubernetes, the kubectl apply command performs an overwrite update, whereas the kubectl edit command performs an incremental update based on the existing object. For an ALB instance already created through an AlbConfig, use the kubectl edit command to incrementally update the instance configuration. The following steps describe how to update an AlbConfig.
Run the following command to view the AlbConfig.
kubectl -n kube-system get AlbConfigExpected output:
NAME ALBID DNSNAME PORT&PROTOCOL CERTID AGE alb-demo alb-****** alb-******.<regionID>.alb.aliyuncs.com 443/HTTPS 11055487-cn-<regionID> 2dRun the following command to update the AlbConfig.
ImportantWe recommend using the
kubectl editcommand to directly update resource configurations. If you must use thekubectl applycommand to update a resource, run thekubectl diffcommand to preview the changes before you run thekubectl applycommand. Ensure that the changes are as expected, and then use thekubectl applycommand to apply the changes to the Kubernetes cluster.When you use the
kubectl applycommand to overwrite an AlbConfig, the behavior depends on whether the YAML file includes thelistenersfield. If the field is not included, existing listeners are not affected. If the field is included, listeners are reconciled to match the current configuration. Therefore, you must specify the full list of required listeners, such as the common listeners for ports 80 and 443.
kubectl -n kube-system edit AlbConfig alb-demoIn the AlbConfig configuration file, update the content. For example, update the name of the AlbConfig to
test.... spec: config: name: test # Enter the updated name. ...
Associate an AlbConfig with an Ingress
You can associate an Ingress with an AlbConfig by using a standard Kubernetes IngressClass. First, create an IngressClass that references the AlbConfig, then specify that IngressClass in your Ingress resource.
Create a file named alb.yaml and copy the following content into it to create an IngressClass.
apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: name: alb spec: controller: ingress.k8s.alibabacloud/alb parameters: apiGroup: alibabacloud.com kind: AlbConfig name: alb-demoRun the following command to create the IngressClass.
kubectl apply -f alb.yamlExpected output:
ingressclass.networking.k8s.io/alb createdCreate a file named ingress.yaml and copy the following content into it. The
ingressClassNameparameter specifies the IngressClass namedalbto associate with the AlbConfig.apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: cafe-ingress spec: ingressClassName: alb rules: - http: paths: # Configure the context path. - path: /tea pathType: ImplementationSpecific backend: service: name: tea-svc port: number: 80 # Configure the context path. - path: /coffee pathType: ImplementationSpecific backend: service: name: coffee-svc port: number: 80Run the following command to create the Ingress.
kubectl apply -f ingress.yamlExpected output:
ingress.networking.k8s.io/cafe-ingress created
After you complete these steps, the AlbConfig is associated with the Ingress by using the IngressClass.
Modify the name of an ALB instance
Run the following command to modify the name of an ALB instance:
kubectl -n kube-system edit AlbConfig alb-demoModify the value of config.name in the configuration file. The new name takes effect automatically after you save the file.
...
spec:
config:
name: test # Enter the updated name.
...Use an IPv6 address
To enable IPv6 support when you create an ALB instance, set the addressIpVersion field to DualStack in the AlbConfig.
The addressIpVersion field takes effect only during instance creation and cannot be modified afterward.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: alb-demo
spec:
config:
addressIpVersion: DualStack
...Specify a TLS security policy
You can specify a TLS security policy for an HTTPS listener in an AlbConfig. TLS security policies include custom policies and system policies. For more information, see TLS security policies.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: alb-demo
spec:
config:
#...
listeners:
- port: 443
protocol: HTTPS
securityPolicyId: tls_cipher_policy_1_1
#...Enable access logs
To enable access logging for the ALB Ingress, specify a logProject and logStore in your AlbConfig.
You must create the
logProjectmanually. For more information about how to create alogProject, see Manage a Project.The name of the
logStoremust start withalb_. If the specifiedlogStoredoes not exist, it is automatically created.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: alb-demo
spec:
config:
accessLogConfig:
logProject: "k8s-log-xz92lvykqj1siwvif****"
logStore: "alb_****"
#...After you save the configuration, you can navigate to the Log Service console and select the destination LogStore to view the collected access logs.
Reuse an existing ALB instance
To reuse an existing ALB instance, specify the ALB instance ID when you create the AlbConfig. The existing ALB instance must be a Standard or WAF-enabled edition instance created in the Application Load Balancer (ALB) console. Basic edition ALB instances cannot be reused. An ALB instance can be reused only by a single AlbConfig within the same cluster. Reusing one ALB instance across multiple clusters is not supported, nor is reusing one ALB instance by multiple AlbConfigs within the same cluster.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: reuse-alb
spec:
config:
id: **** # The ID of the Standard or WAF-enabled edition ALB instance created in the ALB console.
forceOverride: false
listenerForceOverride: falseThe following table describes the parameters.
Parameter | Description |
id |
Important When reusing an instance, do not manually modify listener names. Doing so can cause ACS to mismanage the listeners. Listeners created or updated by an AlbConfig are managed by ACS, and the listener names are in the |
forceOverride | Specifies whether to forcibly overwrite the attributes of the ALB instance in reuse mode.
|
listenerForceOverride | Specifies whether to forcibly overwrite listener attributes in reuse mode.
|
Create a listener
In a reuse scenario, you can add a new listener or edit the settings of an existing listener by modifying the AlbConfig. Run the command kubectl edit albconfig <Albconfig_Name>. Set the port and protocol in the AlbConfig to create the corresponding listener. The port and protocol are the unique properties of a listener. If you modify the port, protocol, or other properties of the listener, the system deletes the original listener and creates a new one to replace it.
The HTTP protocol is automatically compatible with WebSocket and does not require special settings.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: alb-demo
spec:
config:
...
listeners:
- port: 80
protocol: HTTP # Valid values for protocol are HTTP, HTTPS, and QUIC.
...Create and use multiple ALB instances
To use multiple ALB instances, specify a different IngressClass for each Ingress resource by using the spec.ingressClassName parameter.
Create a file named alb-demo2.yaml and copy the following content into it to create an AlbConfig.
apiVersion: alibabacloud.com/v1 kind: AlbConfig metadata: name: demo spec: config: name: alb-demo2 # The name of the ALB instance. addressType: Internet # The load balancer has a public IP address. zoneMappings: # For high availability, select vSwitches in at least two different zones. - vSwitchId: vsw-uf6ccg2a9g71hx8go**** # Replace with the actual vSwitch ID (Zone 1). - vSwitchId: vsw-uf6nun9tql5t8nh15**** # Replace with the actual vSwitch ID (Zone 2, must be different from Zone 1).Run the following command to create the AlbConfig.
kubectl apply -f alb-demo2.yamlExpected output:
AlbConfig.alibabacloud.com/demo createdCreate a file named alb.yaml and copy the following content into it to create an IngressClass.
apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: name: alb-demo2 spec: controller: ingress.k8s.alibabacloud/alb parameters: apiGroup: alibabacloud.com kind: AlbConfig name: demoRun the following command to create the IngressClass.
kubectl apply -f alb.yamlExpected output:
ingressclass.networking.k8s.io/alb-demo2 createdCreate a file named
ingress.yamland copy the following content into it. Use theingressClassNameparameter to specify different ALB instances.apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: demo namespace: default spec: ingressClassName: alb-demo2 rules: - host: "" http: paths: - backend: service: name: demo-service port: number: 80 path: /hello pathType: ImplementationSpecific
Set the listener request timeout
In an AlbConfig, you can specify a listener and set the connection request timeout in seconds. The value must be in the range of 1 to 180. If a backend server does not respond within the timeout period, the load balancer returns an HTTP 504 error to the client. The default timeout is 60 seconds.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
...
listeners:
- port: 80
protocol: HTTP
requestTimeout: 60
...Use data compression
In an AlbConfig, you can specify a listener and enable or disable data compression. The following list describes the valid values of gzipEnabled.
true: Compresses specific types of files.
false: Does not compress any types of files.
Brotli supports the compression of all file types. Gzip supports the compression of the following file types: text/xml, text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, application/atom+xml, application/xml, and application/json.
The following code provides a YAML sample for disabling data compression:
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
...
listeners:
- port: 80
protocol: HTTP
gzipEnabled: false
...Retrieve client IP addresses
You can configure the listener to include the X-Forwarded-For header field, which allows backend servers to retrieve the client's real IP address. The following list describes the valid values of XForwardedForEnabled.
true: Retrieves the real IP addresses of clients.
false: Does not retrieve the real IP addresses of clients.
You can configure this parameter for only HTTP and HTTPS listeners.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
#...
listeners:
- port: 80
protocol: HTTP
xForwardedForConfig:
XForwardedForEnabled: true
#...Retrieve the listener protocol
In AlbConfig, you can use the XForwardedForProtoEnabled field to retrieve the listener protocol of the instance. The values are as follows:
true: Retrieves the listener protocol of the instance.
false: Does not retrieve the listener protocol of the instance.
You can configure this parameter for only HTTP and HTTPS listeners.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
...
listeners:
- port: 80
protocol: HTTP
xForwardedForConfig:
XForwardedForProtoEnabled: true
...Retrieve the load balancer ID
You can configure the listener to include the SLB-ID header, which allows backend servers to retrieve the ID of the load balancer instance. The following list describes the valid values of XForwardedForSLBIdEnabled.
true: Retrieves the ID of the load balancer instance.
false: Does not retrieve the ID of the load balancer instance.
You can configure this parameter for only HTTP and HTTPS listeners.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
...
listeners:
- port: 80
protocol: HTTP
xForwardedForConfig:
XForwardedForSLBIdEnabled: true
...Retrieve the listener port
You can configure the listener to include the X-Forwarded-Port header, which allows backend servers to retrieve the listener port of the instance. The following list describes the valid values of XForwardedForSLBPortEnabled.
true: Retrieves the listener port of the instance.
false: Does not retrieve the listener port of the instance.
You can configure this parameter for only HTTP and HTTPS listeners.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
...
listeners:
- port: 80
protocol: HTTP
xForwardedForConfig:
XForwardedForSLBPortEnabled: true
...Retrieve the client port
You can configure the listener to include the X-Forwarded-Client-srcport header, which allows backend servers to retrieve the client's source port. The following list describes the valid values of XForwardedForClientSrcPortEnabled.
true: Retrieves the client port of the load balancer instance.
false: Does not retrieve the client port of the load balancer instance.
You can configure this parameter for only HTTP and HTTPS listeners.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
...
listeners:
- port: 80
protocol: HTTP
xForwardedForConfig:
XForwardedForClientSrcPortEnabled: true
...Configure ACL access control
You can use an AlbConfig to enable access control for an ALB listener. By setting allow or deny rules for inbound traffic, you can precisely control client requests and manage request forwarding. For more information about access control lists (ACLs), see Access control.
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
#...
listeners:
- port: 80
protocol: HTTPS
aclConfig:
aclEntries:
- 127.0.0.1/32
aclType: White
#...The following list describes some of the parameters:
aclType: Specifies whether the ACL of the listener is a blacklist or a whitelist. Valid values: Black (blacklist) and White (whitelist).
aclEntries: Specifies the IP address ranges for access control entries, such as 127.0.0.1/32.
Delete an ALB instance
An ALB instance corresponds to an AlbConfig. Therefore, you can delete an AlbConfig to delete the corresponding ALB instance. Before you delete the AlbConfig, you must delete all Ingresses that are associated with it.
kubectl delete -n kube-system AlbConfig alb-demoReplace alb-demo with the name of the AlbConfig that you want to delete.
Delete the AlbConfig for a reused instance
If you want to delete the AlbConfig of a reused ALB instance, perform the following steps.
Delete all Ingresses that are associated with the AlbConfig.
kubectl delete -n <NAMESPACE> ingress <INGRESS_NAME> # Replace <INGRESS_NAME> and <NAMESPACE> with the name and namespace of the Ingress that you want to delete.Use the
kubectl editcommand to modify the AlbConfig and delete all of its listeners. To do this, delete all entries under thespec.listenersfield.ImportantPerform this step only if your ALB Ingress Controller version is v2.10.0-aliyun.1 or earlier.
Delete the AlbConfig.
kubectl -n kube-system delete AlbConfig alb-demo # Replace alb-demo with the name of the AlbConfig that you want to delete.