All Products
Search
Document Center

Microservices Engine:Manage services in multiple ACK clusters by using a cloud-native gateway

Last Updated:May 10, 2024

To ensure service stability, you can deploy multiple Container Service for Kubernetes (ACK) clusters in a peer-to-peer manner to achieve high availability. A cloud-native gateway supports access from multiple ACK clusters. A gateway is associated with multiple clusters, combines services with identical names, and implements load balancing among multiple services. You can use the feature together with the health check feature of the gateway to automatically detect service availability and implement automatic traffic switching upon failures in an efficient manner. This topic describes how to use a cloud-native gateway to manage two ACK clusters.

Prerequisites

  • Two ACK clusters are created. For more information about how to create an ACK cluster, see Create an ACK managed cluster.

  • Services with identical names are deployed in the two ACK clusters. The following sample code is used for a service named httpbin.

    Show YAML code

    apiVersion: v1
    kind: Service
    metadata:
      name: httpbin
      labels:
        app: httpbin
    spec:
      ports:
      - name: http
        port: 8000
        targetPort: 80
      selector:
        app: httpbin
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: httpbin
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: httpbin
          version: v1
      template:
        metadata:
          labels:
            app: httpbin
            version: v1
        spec:
          containers:
          - image: docker.io/kennethreitz/httpbin
            imagePullPolicy: IfNotPresent
            name: httpbin
            ports:
            - containerPort: 80

Background information

In production practices, if high business stability is required, you can deploy multiple ACK clusters in a peer-to-peer manner to ensure high availability. For example, Cluster A is deployed in Zone A and Cluster B is deployed in Zone B. The same services are deployed in the two clusters. If a cluster fails, traffic is switched to services in the other cluster.

Cloud-native gateways provide the multi-cluster access feature to meet the high-availability deployment requirements of your business. If a cloud-native gateway is associated with both Cluster A and Cluster B, the gateway combines the services with identical names in the two clusters into one service. The name of the combined service is the same as the original service names, but the IP address list of the combined service contains all the IP addresses of the two services. If Cluster A or B fails, all traffic is automatically distributed to the normal cluster by using the routing capability of the cloud-native gateway. We recommend that you use this feature together with the active health check feature of the gateway. The active health check feature allows the gateway to actively detect the IP address availability of services. This helps implement automatic traffic switchover.

In the following figure, a cloud-native gateway manages Services A and B in two ACK clusters. If a crash occurs in Cluster B, you can still access Services A and B in Cluster A by using the gateway. All traffic is automatically switched to Cluster A without human intervention.

image

Step 1: Add ACK service sources to the cloud-native gateway

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the name of the gateway.

  3. In the left-side navigation pane, click Routes. On the page that appears, click the Sources tab.

  4. On the Sources tab, click Add Source. In the Add Source panel, configure the parameters and click OK. For more information, see Add a service source.

    创建容器来源.png

Step 2: Add Services A and B to the cloud-native gateway

  1. In the left-side navigation pane, click Routes. On the page that appears, click the Services tab.

  2. On the Services tab, click Add Service. In the Add Service panel, configure the parameters and click OK. For more information, see Add a service.

    没有删除一个服务.png

Step 3: Add a routing rule for the services in the cloud-native gateway

  1. In the left-side navigation pane, click Routes, and click the Routes tab.

  2. On the Routes tab, click Add Route. On the Add Route page, configure the parameters and click Save and Release. For more information, see Create a route.

    创建路由222.png

Verify the result

Clusters A and B are normal

  1. On the Services tab, view the IP addresses of the service.

    Two IP addresses are displayed, as shown in the following figure.没删除服务.png

  2. Access the gateway multiple times to generate access logs. Sample code:

    while :; do curl http://<IP address of the SLB instance associated with the gateway>/test ; done
  3. Query and analyze gateway logs.

    1. Log on to the MSE console.

    2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. In the top navigation bar, select a region.

    3. On the Gateways page, click the name of the gateway.

    4. In the left-side navigation pane, choose Observation Analysis > Log Center. In the upper-right corner of the Log Center page, select Log Service.

      image.png

      You can query the IP addresses of the service in the clusters based on upstream_host. upstream_host has two values, as shown in the following figure. This indicates that traffic is evenly distributed to two ACK clusters.

      image..png

Cluster A fails

  1. Remove the httpbin service from Cluster A.

    In this case, only one IP address is available, as shown in the following figure.

    删除一个服务.png

  2. Access the gateway multiple times to generate access logs. Sample code:

    while :; do curl http://<IP address of the SLB instance associated with the gateway>/test ; done
  3. Query and analyze gateway logs.

    1. Log on to the MSE console.

    2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. In the top navigation bar, select a region.

    3. On the Gateways page, click the name of the gateway.

    4. In the left-side navigation pane, choose Observation Analysis > Log Center. In the upper-right corner of the Log Center page, select Log Service.

      image..png

      upstream_host has only one value, as shown in the following figure. The value indicates the IP address of the service in Cluster B. This indicates that the gateway distributes all traffic to Cluster B.

      image..png