Ingresses function as Layer-7 load balancers for Kubernetes clusters. Configured Ingress rules precisely route external requests to designated backend Services or applications. Through multi-cluster Services and Ingress rules, requests can be distributed across Services deployed in multiple clusters. This topic describes how to work with multi-cluster Ingresses.
Prerequisites
The Fleet management feature is enabled.
The Fleet instance is associated with multiple clusters whose Kubernetes versions are 1.21 or later. For more information, see Associate clusters with a Fleet instance.
The kubeconfig file of the Fleet instance is obtained in the Distributed Cloud Container Platform for Kubernetes (ACK One) console and a kubectl client is connected to the Fleet instance.
The AMC command-line tool is installed.
A multi-cluster Service is created and associated with the backend applications and Services to which the Ingresses route requests. For more information, see MCS overview.
The NGINX Ingress controller is installed in the clusters that are configured with Ingresses and the version of the NGINX Ingress controller is 1.7.0-aliyun.1 or later. For more information, see Update the NGINX Ingress controller.
Usage notes
After configuring multi-cluster Services and Ingress rules, you can route requests to Services deployed across multiple clusters. The following figure shows the workflow:
In this example, Ingresses are created for ACK Cluster 1 and ACK Cluster 2. Applications are deployed in ACK Cluster 1, ACK Cluster 2, and ACK Cluster 3. The following figure shows how multi-cluster Ingresses are used to route requests.
Procedure
Map a multi-cluster Service to the Services in the clusters that are configured with Ingresses.
For more information about how to configure a multi-cluster Service, see Use the CLI to configure MCS.
Configure a ServiceExport in each cluster to export the Service in the cluster to the multi-cluster Service.
Configure a ServiceImport in each cluster that is configured with an Ingress. The ServiceImport is used to import the multi-cluster Service to the cluster so that the Ingress of the cluster can access the multi-cluster Service. By default, the imported Services are named in the
amcs-{Service name}format.Run the following command in the clusters that are configured with Ingresses to query the imported Services:
kubectl get service amcs-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE amcs-nginx ClusterIP 192.168.118.171 <none> 80/TCP 34m kubectl get endpointslice NAME ADDRESSTYPE PORTS ENDPOINTS AGE imported-c0c4a2c9339e44235a5228d0b0ff2259c-nginx-vnlnd IPv4 80 10.0.2.4,10.0.2.5 34m imported-ce962c460ae284243a3161d6f2c7b4cf7-nginx-d8rr5 IPv4 80 10.0.2.221,10.0.2.236 29m imported-ca5b667538054499ab399588efe4ab654-nginx-xfe1a IPv4 80 10.0.2.145,10.0.2.123 20m
Configure Ingress rules in the clusters that are configured with Ingresses to expose Services.
Create a file named ingress.yaml and copy the following content to the file:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: multi-cluster-nginx-ingress spec: rules: - host: example.com http: paths: - path: / pathType: Prefix backend: service: name: amcs-nginx port: 80Run the following command to configure Ingress rules in the clusters that are configured with Ingresses to route requests to the multi-cluster Service:
kubectl apply -f ingress.yamlQuery the Ingress endpoints of the clusters that are configured with Ingresses.
# ACK Cluster 1 kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE multi-cluster-nginx-ingress nginx example.com XX.XX.XX.XX 80 26m # ACK Cluster 2 kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE multi-cluster-nginx-ingress nginx example.com XX.XX.XX.XX 80 26m
Use DNS resolution to resolve the Ingress domain names.
Create A records to resolve the Ingress domain names to the Ingress addresses of the clusters that are configured with Ingresses. For more information about domain name resolution, see Add DNS records.