All Products
Search
Document Center

Container Service for Kubernetes:Use ALB Ingresses to configure hybrid server groups, associate ECS instances with an ALB instance deployed in a different region, and associate on-premises servers with an ALB instance

Last Updated:Oct 12, 2023

Application Load Balancer (ALB) Ingresses allow you to use the alb.ingress.kubernetes.io/actions.<Service name> annotation to configure server groups for Services. You can associate pods deployed in a cluster and Elastic Compute Service (ECS) instances deployed outside the cluster with a Service by specifying the name of the Service or the ID of the server group. To associate ECS instances with an ALB instance deployed in a virtual private cloud (VPC) in a different region, use a combination of ALB, transit routers, and Cloud Enterprise Network (CEN). You can also use this method to associate on-premises servers with an ALB instance. This topic describes how to configure hybrid server groups, associate ECS instances with an ALB instance deployed in a different region, and associate on-premises servers with an ALB instance.

Table of contents

Usage notes

  • The Service name in the alb.ingress.kubernetes.io/actions.<Service name> annotation must be the same as that below the backend field in the rules section.

  • When you configure server groups, you must set the Service port name below the backend field in the rules section to use-annotation.

  • You can use the alb.ingress.kubernetes.io/actions.<Service name> annotation to associate multiple server groups with an ALB instance.

  • You can associate up to five server groups with a basic ALB instance.

  • The ServerGroupID setting prevails when you use both the ServerGroupID and ServiceName+ServicePort settings to associate server groups.

Scenario 1: Forward requests to multiple Services in an ACK cluster or ACK Serverless cluster

Prerequisites

Scenario

In the following figure, the ServiceName+ServicePort setting is used to associate multiple server groups with the ALB Ingress. Multiple forwarding rules are configured for the ALB Ingress to forward requests to different Services in the cluster.

场景一

Procedure

  1. Configure an ALB Ingress.

    Create a file named tea-ingress.yaml and add the following content to the file. Deploy this file to forward requests to multiple Services in the cluster.

    # Forward requests to different Services based on the hostname and path of the requests and specify the weight of each Service. 
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: tea-ingress
      annotations:
        alb.ingress.kubernetes.io/actions.forward: |
           [{
               "type": "ForwardGroup",
               "ForwardConfig": {
                 "ServerGroups" : [{
                   "ServiceName": "tea-svc",
                   "Weight": 80,
                   "ServicePort": 80
                 },
                 {
                   "ServiceName": "coffee-svc",
                   "Weight": 20,
                   "ServicePort": 80
                 }]
               }
           }]
    spec:
      ingressClassName: alb
      rules:
       - host: demo.domain.ingress.top
         http:
          paths:
          - path: /path
            pathType: Prefix
            backend:
              service:
                name: forward
                port:
                  name: use-annotation
  2. Access the Services by using a CLI. For more information, see Access Services.

Scenario 2: Forward requests to the pods deployed in an ACK cluster or ACK Serverless cluster and ECS instances deployed outside the cluster

Prerequisites

Scenario

In the following figure, the ALB Ingress is used to forward requests to the pods deployed in the cluster and the ECS instance deployed outside the cluster. To do this, you need to create a server group in the ALB console or by calling the ALB API, and add the ECS instance to the server group. Then, record the server group ID and specify the ID in the configuration of the ALB Ingress.

image.png

Procedure

  1. Configure an ALB Ingress.

    Create a file named tea-ingress.yaml and add the following content to the file. Deploy this file to forward requests to the pods in the cluster and the ECS instance outside the cluster.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: tea-ingress
      annotations:
        alb.ingress.kubernetes.io/actions.forward: |
           [{
               "type": "ForwardGroup",
               "ForwardConfig": {
                 "ServerGroups" : [{
                   "ServiceName": "tea-svc",
                   "Weight": 30,
                   "ServicePort": 80
                 },
                 {
                   "ServiceName": "coffee-svc",
                   "Weight": 20,
                   "ServicePort": 80
                 },
                 {
                   "ServerGroupID": "sgp-71aexb9y93ypo*****",
                   "Weight": 30
                 },
                 {
                   "ServerGroupID": "sgp-slygpbvm2cydo*****",
                   "Weight": 20
                 }]
               }
           }]
    spec:
      ingressClassName: alb
      rules:
       - host: demo.domain.ingress.top
         http:
          paths:
          - path: /path
            pathType: Prefix
            backend:
              service:
                name: forward
                port:
                  name: use-annotation
  2. Access the Service by using a CLI. For more information, see Access Services.

Scenario 3: Forward requests to the pods in a cluster and ECS instances in a VPC deployed in a different region

Prerequisites

Scenario

In the following figure, the ALB Ingress is used to forward requests to the pods in the cluster and the ECS instance in a VPC deployed in a different region. To do this, you need to create a CEN instance, attach VPC1 and VPC2 to the CEN instance, and add the ECS instance in VPC2 to a server group. Then, record the server group ID and specify the ID in the configuration of the ALB Ingress.

场景三

For example, an ACK cluster or ACK Serverless cluster is created in VPC1 in the China (Chengdu) region and an ALB instance is created from an ALBConfig in VPC1. You can use ALB together with CEN to forward requests to the ECS instance in VPC2 in the China (Hangzhou) region.

异地挂载

Procedure

  1. Configure a CEN instance and create inter-region VPC connections.

    For more information, see Specify an ECS instance in a VPC as a backend server of ALB in a different region.

    Note

    You do not need to configure listeners in the ALB console for the ALB instance used by the ALB Ingress. You can perform Step 3 to configure listeners.

  2. Add the ECS instance in VPC2 to a server group of the ALB instance.

    For more information, see Add backend servers.

  3. Use the alb.ingress.kubernetes.io/actions.<Service name> annotation to configure forwarding rules, associate the server group with the ALB Ingress, and forward requests to the pods in the cluster and the ECS instance in VPC2.

    Create a file named tea-ingress.yaml and add the following content to the file:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: tea-ingress
      annotations:
        alb.ingress.kubernetes.io/actions.forward: |
           [{
               "type": "ForwardGroup",
               "ForwardConfig": {
                 "ServerGroups" :  [{
                   "ServiceName": "tea-svc",
                   "Weight": 30,
                   "ServicePort": 80
                 },
                 {
                   "ServiceName": "coffee-svc",
                   "Weight": 20,
                   "ServicePort": 80
                 },
                 {
                   "ServerGroupID": "sgp-71aexb9y93ypo*****",
                   "Weight": 30
                 },
                 {
                   "ServerGroupID": "sgp-slygpbvm2cydo*****",
                   "Weight": 20
                 }]
               }
           }]
    spec:
      ingressClassName: alb
      rules:
       - host: demo.domain.ingress.top
         http:
          paths:
          - path: /path
            pathType: Prefix
            backend:
              service:
                name: forward
                port:
                  name: use-annotation

Scenario 4: Forward requests to the pods in a cluster and on-premises servers

Prerequisites

Usage notes

For more information about the usage notes for associating on-premises servers with ALB instances, see Usage notes.

Scenario

In the following figure, the ALB Ingress is used to forward requests to the pods in the cluster and on-premises servers. To do this, you need to configure a CEN instance, an Express Connect circuit, and a VBR, and add on-premises servers to a server group. Then, record the server group ID and specify the ID in the configuration of the ALB Ingress.

场景四

For example, an ACK cluster or ACK Serverless cluster is deployed in VPC1 in the China (Chengdu) region and an ALB instance is created from an ALBConfig in the VPC. You can use a combination of ALB, CEN, VBRs, and Express Connect to forward requests to on-premises servers in the region. The following figure shows the architecture.

挂载本地IDC

Procedure

  1. Configure a CEN instance, attach the VBR and VPC1 in which the ALB instance resides to the transit router, and use the VBR to connect the data center to Alibaba Cloud. For more information, see Specify an on-premises server as a backend server of ALB.

    Note

    You do not need to configure listeners in the ALB console for the ALB instance used by the ALB Ingress. You can perform Step 3 to configure listeners.

  2. Use the alb.ingress.kubernetes.io/actions.<Service name> annotation to configure forwarding rules, associate the server group with the ALB Ingress, and forward requests to the pods in the cluster and on-premises servers.

    Create a file named tea-ingress.yaml and add the following content to the file:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: tea-ingress
      annotations:
        alb.ingress.kubernetes.io/actions.forward: |
           [{
               "type": "ForwardGroup",
               "ForwardConfig": {
                 "ServerGroups" :  [{
                   "ServiceName": "tea-svc",
                   "Weight": 30,
                   "ServicePort": 80
                 },
                 {
                   "ServiceName": "coffee-svc",
                   "Weight": 20,
                   "ServicePort": 80
                 },
                 {
                   "ServerGroupID": "sgp-ihydxb9y93ypo*****",
                   "Weight": 30
                 },
                 {
                   "ServerGroupID": "sgp-pd0ipbvm2cydo*****",
                   "Weight": 20
                 }]
               }
           }]
    spec:
      ingressClassName: alb
      rules:
       - host: demo.domain.ingress.top
         http:
          paths:
          - path: /path
            pathType: Prefix
            backend:
              service:
                name: forward
                port:
                  name: use-annotation