Application Load Balancer (ALB) Ingresses support HTTP, HTTPS, and QUIC protocols and provide high elasticity and Layer 7 traffic management for cloud-native applications at scale. ALB Ingresses are compatible with NGINX Ingresses and support complex routing rules and automatic TLS certificate management. Use this guide to configure an ALB Ingress end-to-end and access backend Services in your cluster by path-based routing.
Prerequisites
Before you begin, make sure that you have:
-
A registered cluster with an external cluster deployed in a data center connected to it. For more information, see Create a registered cluster in the ACK console.
-
Your Kubernetes cluster version available. Steps 1 and 3 include separate manifests for clusters running Kubernetes versions earlier than 1.19 and for clusters running Kubernetes 1.19 or later.
How it works
Configuring ALB Ingress involves creating three Kubernetes objects in sequence:
-
AlbConfig — defines the ALB instance (address type, vSwitch assignments).
-
IngressClass — links the
albclass name to the AlbConfig. -
Ingress — maps URL paths to backend Services, referencing the IngressClass.
Once applied, the ALB Ingress controller provisions an ALB instance and configures forwarding rules based on the Ingress spec.
Step 1: Create an AlbConfig object
-
Create a file named
alb-test.yamlwith the following content:apiVersion: alibabacloud.com/v1 kind: AlbConfig metadata: name: alb-demo spec: config: name: alb-test addressType: Internet zoneMappings: - vSwitchId: vsw-uf6ccg2a9g71hx8go**** - vSwitchId: vsw-uf6nun9tql5t8nh15****Parameter Required Description spec.config.nameNo Name of the ALB instance. spec.config.addressTypeYes Type of IP address the ALB instance uses. Internet(default): uses a public IP address, accessible over the internet.Intranet: uses a private IP address, accessible only within the virtual private cloud (VPC) where the instance is deployed.spec.config.zoneMappingsYes vSwitch IDs for the ALB Ingress. Specify at least two vSwitch IDs in different zones within the VPC where the cluster resides. The zones of the vSwitches must be supported by ALB Ingresses. For supported regions and zones, see Supported regions and zones. -
Apply the AlbConfig:
kubectl apply -f alb-test.yamlExpected output:
albconfig.alibabacloud.com/alb-demo created -
Create a file named
alb.yamlto define the IngressClass. Clusters running Kubernetes versions earlier than 1.19apiVersion: networking.k8s.io/v1beta1 kind: IngressClass metadata: name: alb spec: controller: ingress.k8s.alibabacloud/alb parameters: apiGroup: alibabacloud.com kind: AlbConfig name: alb-demoClusters running Kubernetes 1.19 or later
apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: name: alb spec: controller: ingress.k8s.alibabacloud/alb parameters: apiGroup: alibabacloud.com kind: AlbConfig name: alb-demo -
Apply the IngressClass:
kubectl apply -f alb.yamlExpected output:
ingressclass.networking.k8s.io/alb created
Step 2: Deploy Services
-
Create a file named
cafe-service.yamlwith the following content. This deploys two Deployments (coffeeandtea) and their corresponding Services.apiVersion: apps/v1 kind: Deployment metadata: name: coffee spec: replicas: 2 selector: matchLabels: app: coffee template: metadata: labels: app: coffee spec: containers: - name: coffee image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: coffee-svc spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: app: coffee clusterIP: None --- apiVersion: apps/v1 kind: Deployment metadata: name: tea spec: replicas: 1 selector: matchLabels: app: tea template: metadata: labels: app: tea spec: containers: - name: tea image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: tea-svc labels: spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: app: tea clusterIP: None -
Apply the file:
kubectl apply -f cafe-service.yamlExpected output:
deployment "coffee" created service "coffee-svc" created deployment "tea" created service "tea-svc" created -
Verify that the Deployments and Services are running. Check Deployment status:
kubectl get deployExpected output:
NAME READY UP-TO-DATE AVAILABLE AGE coffee 1/2 2 1 2m26s tea 1/1 1 1 2m26sCheck Service status:
kubectl get svcExpected output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE coffee-svc NodePort 172.16.XX.XX <none> 80:32056/TCP 9m38s tea-svc NodePort 172.16.XX.XX <none> 80:31696/TCP 9m38s
Step 3: Configure an ALB Ingress
-
Create a file named
cafe-ingress.yamlwith the following content. Clusters running Kubernetes versions earlier than 1.19apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: cafe-ingress spec: ingressClassName: alb rules: - host: demo.domain.ingress.top http: paths: # Configure a context path. - path: /tea backend: serviceName: tea-svc servicePort: 80 # Configure a context path. - path: /coffee backend: serviceName: coffee-svc servicePort: 80Clusters running Kubernetes 1.19 or later
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: cafe-ingress spec: ingressClassName: alb rules: - host: demo.domain.ingress.top http: paths: # Configure a context path. - path: /tea pathType: ImplementationSpecific backend: service: name: tea-svc port: number: 80 # Configure a context path. - path: /coffee pathType: ImplementationSpecific backend: service: name: coffee-svc port: number: 80 -
Apply the Ingress:
kubectl apply -f cafe-ingress.yamlExpected output:
ingress.networking.k8s.io/cafe-ingress created -
Retrieve the domain name assigned to the ALB Ingress:
kubectl get ingExpected output:
NAME CLASS HOSTS ADDRESS PORTS AGE cafe-ingress alb demo.domain.ingress.top alb-m551oo2zn63yov****.cn-hangzhou.alb.aliyuncs.com 80 50sThe ALB instance is ready when the
ADDRESSfield is populated. This may take a few minutes.
Step 4: Access the Services
Use the ALB domain name from the previous step to send requests to each Service.
Access the coffee Service:
curl -H Host:demo.domain.ingress.top http://alb-lhwdm5c9h8lrcm****.cn-hangzhou.alb.aliyuncs.com/coffee
Access the tea Service:
curl -H Host:demo.domain.ingress.top http://alb-lhwdm5c9h8lrcm****.cn-hangzhou.alb.aliyuncs.com/tea
What's next
-
For advanced configurations such as forwarding requests by domain name or URL, health checks, HTTP-to-HTTPS redirects, canary releases, and custom listener ports, see Advanced ALB Ingress configurations.
-
To learn how AlbConfig works with the ALB Ingress controller to configure ALB instances and listeners, see Use AlbConfigs to configure ALB instances.