All Products
Search
Document Center

Container Service for Kubernetes:Customize ALB Ingress forwarding rules using console or annotations

Last Updated:Aug 25, 2026

ALB Ingress extends a native Kubernetes Ingress with custom forwarding rules, allowing you to specify conditions such as the request header, query string, request method, cookie, and source IP, and to define custom forwarding actions such as a fixed response, redirection, or traffic mirroring. Some of these custom forwarding rules can be configured in the console.

How it works

ALB custom forwarding rules consist of forwarding conditions and forwarding actions that provide fine-grained traffic control for both requests and responses:

  • Forwarding condition: Configured using the alb.ingress.kubernetes.io/conditions.<service_name> annotation. This condition is associated with a backend Service by name and applies to all paths in the Ingress that route to that Service. Only traffic that meets the condition triggers the corresponding action. The condition can match traffic in both the request and response directions.

  • Forwarding action: Configured using the alb.ingress.kubernetes.io/actions.<service_name> annotation. It defines the specific behavior of an ALB instance when handling a request or response, such as forwarding traffic or issuing a redirect.

  • Rule direction: Use the alb.ingress.kubernetes.io/rule-direction.<service_name> annotation to specify whether a custom forwarding rule applies to the request or response direction:

    • Request direction: A client request is forwarded through the ALB Ingress to a backend Service.

    • Response direction: A backend Service response is forwarded through the ALB Ingress back to the client.

    • When a forwarding condition and a forwarding action are configured for the same direction, the action is triggered only for traffic that meets the forwarding condition.

Important

Because thealb.ingress.kubernetes.io/rule-direction.<service_name> annotation applies to all configurations within the current Ingress resource, configure forwarding rules for the request and response directions in separate Ingress resources. For a configuration example, see Scenario 7: Modify response headers based on ResponseHeader.

Prerequisites

Install the component

Install the ALB Ingress Controller, or ensure that the installed version is v2.5.0 or later.

Create a sample Service

Copy the following example to a file named echoserver.yaml and run kubectl apply -f echoserver.yaml to create a sample Deployment and Service. This example uses an echoserver image that echoes received requests. You can use this setup to verify your ALB custom forwarding rules.

Important

The sample images used in this topic are public images. Your cluster or nodes must have public network access to pull them:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echoserver
  labels:
    app: echoserver
spec:
  replicas: 2
  selector:
    matchLabels:
      app: echoserver
  template:
    metadata:
      labels:
        app: echoserver
    spec:
      containers:
      - name: echoserver
        image: openkruise-registry.cn-shanghai.cr.aliyuncs.com/openkruise/demo:1.10.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: echoserver
  labels:
    app: echoserver
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
    name: http
  selector:
    app: echoserver

Configure forwarding conditions

Important

After you create an Ingress and set path-based forwarding conditions in the ACK console, ACK automatically adds two forwarding rules with the path /created-by-<ALB-ID> to the Ingress to meet format requirements.

Scenario 1: Forward by source IP and request header

Important

You can specify a maximum of five source IPs for a single custom forwarding rule.

In the following example, the ALB forwards a request to the backend service only if the request's source IP, request header, and path match the specified conditions.

Create sourceip-header.yaml and copy the following example into it, then run kubectl apply -f sourceip-header.yaml to create the Ingress.

  • Client IP: Matches 192.168.0.0/16 or 10.0.0.0/8.

  • The request header contains headername:headervalue1 or headername:headervalue2.

  • Path: Use /echo.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    alb.ingress.kubernetes.io/conditions.echoserver: | # The name echoserver must match the name of the backend Service configured in spec.rules.
     [{
       "type": "Header",
       "headerConfig": {
         "key": "headername",
         "values": [
           "headervalue1",
           "headervalue2"
         ]
       }
     },
     {
      "type": "SourceIp",
      "sourceIpConfig": {
        "values": [
          "192.168.0.0/16",
          "10.0.0.0/8"
         ]
       }
     }]
  name: sourceip-header-ingress
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              number: 80

Verify the results

Run the following command to send a request that includes a custom header. Replace ALB_ENDPOINT with your ALB instance endpoint.

Make sure that the client IP address is in the SourceIp list.
curl -H "headername:headervalue1" -s ALB_ENDPOINT/echo | grep -A 16 "Request Information"  

Expected output:

Request Information:
	client_address=::ffff:10.0.2.93
	method=GET
	real path=/echo # The path that matches the forwarding condition.
	query=
	request_version=1.1
	request_scheme=http
	request_uri=http://alb-jyoefh22rkje******.******-**.alb.aliyuncsslbintl.com:8080/echo

Request Headers:
	accept=*/*
	headername=headervalue1 # The request header that matches the forwarding condition.
	host=alb-jyoefh22rkje******.******-**.alb.aliyuncsslbintl.com
	remoteip=140.205.***.***
	user-agent=curl/8.4.0
	x-forwarded-for=140.205.***.*** # The source IP that matches the forwarding condition.

Scenario 2: Forward by domain, method, and cookie

In the following example, the ALB forwards a request to the backend service only if the request's domain name, request method, cookie, and path match the specified conditions.

Copy the following example to host-method.yaml, and run kubectl apply -f host-method.yaml to create an Ingress.

  • Domain name: Set to demo.alb.ingress.top in spec.rules.

  • Request method: PUT or HEAD.

  • Cookie: Contains cookiekey1=cookievalue1.

  • Path: Use /echo.

Domain name forwarding conditions support matching for wildcard domain names (such as *.com).
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    alb.ingress.kubernetes.io/conditions.echoserver: | # The name echoserver must match the name of the backend Service configured in spec.rules.
     [{
       "type": "Cookie",
       "cookieConfig": {
         "values": [
           {
             "key":"cookiekey1",
             "value":"cookievalue1"
           }
        ]
       }
      },
      {
       "type": "Method",
       "methodConfig": {
         "values": [
           "PUT",
           "HEAD"
         ]
       }
      }]
  name: host-method-ingress
spec:
  ingressClassName: alb
  rules:
  - host: demo.alb.ingress.top
    http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              number: 80

Verify the results

Run the following command to send a request with a specific domain name, method, and cookie. Replace ALB_ENDPOINT with your ALB instance endpoint.

curl -H "Host:demo.alb.ingress.top" -X PUT -b "cookiekey1=cookievalue1" -s ALB_ENDPOINT/echo | grep -A 16 "Request Information"

Expected output:

Request Information:
	client_address=::ffff:10.0.3.249
	method=PUT # The request method that matches the forwarding condition.
	real path=/echo # The path that matches the forwarding condition.
	query=
	request_version=1.1
	request_scheme=http
	request_uri=http://demo.alb.ingress.top:8080/echo

Request Headers:
	accept=*/*
	cookie=cookiekey1=cookievalue1 # The cookie that matches the forwarding condition.
	host=demo.alb.ingress.top # The domain name that matches the forwarding condition.
	remoteip=140.205.***.***
	user-agent=curl/8.4.0
	x-forwarded-for=140.205.***.***

Scenario 3: Forward by query string and headers

In the following example, the ALB forwards a request to the backend service only if the request's query string, request headers, and path match the specified conditions.

Copy the following example to a querystring.yaml file, and run kubectl apply -f querystring.yaml to create an Ingress.

  • Query string: Use querystringkey1=querystringvalue2.

  • Request header: Contains headerkey1:headervalue1 or headerkey1:headervalue2, and headerkey2:headervalue3 or headerkey2:headervalue4.

  • Path: Use /echo.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    alb.ingress.kubernetes.io/conditions.echoserver: | # The name echoserver must match the name of the backend Service configured in spec.rules.
    [{
      "type": "QueryString",
      "queryStringConfig": {
        "values": [
          {
            "key":"querystringkey1",
            "value":"querystringvalue2"
          }
        ]
      }
    },
    {
      "type": "Header",
      "headerConfig": {
        "key":"headerkey1",
        "values": [
          "headervalue1",
          "headervalue2"
        ]
      }
    },
    {
      "type": "Header",
      "headerConfig": {
        "key":"headerkey2",
        "values": [
          "headervalue3",
          "headervalue4"
        ]
      }
    }]
  name: querystring-ingress
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              number: 80

Verify the results

Run the following command to send a request that includes a specific query string and custom request headers. Replace ALB_ENDPOINT with your ALB instance endpoint.

curl -H "headerkey1:headervalue1" -H "headerkey2:headervalue4" -s "ALB_ENDPOINT/echo?querystringkey1=querystringvalue2" | grep -A 16 "Request Information"

Expected output:

Request Information:
	client_address=::ffff:10.0.3.249
	method=GET
	real path=/echo?querystringkey1=querystringvalue2 # The path that matches the forwarding condition.
	query=querystringkey1=querystringvalue2 # The query string that matches the forwarding condition.
	request_version=1.1
	request_scheme=http
	request_uri=http://alb-jyoefh22rkje******.******-**.alb.aliyuncsslbintl.com/echo?querystringkey1=querystringvalue2

Request Headers:
	accept=*/*
	headerkey1=headervalue1 # The request header that matches the forwarding condition.
	headerkey2=headervalue4 # The request header that matches the forwarding condition.
	host=alb-jyoefh22rkje******.******-**.alb.aliyuncsslbintl.com
	remoteip=140.205.***.***
	user-agent=curl/8.4.0
	x-forwarded-for=140.205.***.***

Forwarding conditions

Important

For information about the logic that applies when multiple forwarding conditions are used together, see Can multiple forwarding conditions of the same type take effect at the same time?

Condition

Description

Domain name

Matches the request's domain name. The ALB forwards only requests with a matching domain name to the backend service.

Forwarding conditions support matching wildcard domain names (for example, *.com).
alb.ingress.kubernetes.io/conditions.service-name: | # service-name must match the name of the backend Service configured in spec.rules.
  [{
      "type": "Host",
      "hostConfig": {
        "values": [
          "anno.example.com"
        ]
      }
  }]
  • type: The matching type of the forwarding condition. Host indicates a match by domain name.

  • hostConfig: The specific domain name to match. If multiple domain names are set, the relationship between them is a logical OR.

Important

This is equivalent to the spec.rules.host field in a native Ingress configuration. If you configure both, an OR relationship is applied between the two domain names. Do not specify the same value for both. Otherwise, the The param is duplicated issue occurs.

Path

Matches the request's path. The ALB forwards only requests with a matching path to the backend service.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name must match the name of the backend Service configured in spec.rules.
  [{
    "type": "Path",
    "pathConfig": {
      "values": [
        "/pathvalue1",
        "/pathvalue2"
      ]
    }
  }]
  • type: The match type for the forwarding condition. Path indicates a match against the request path.

  • pathConfig: The specific path to match. If multiple paths are set, they are evaluated with a logical OR.

Important

This has the same effect as the spec.rules.http.paths.path field in a native Ingress configuration. If both are configured, the two paths have an OR relationship. Do not specify the same content for both paths. Otherwise, a The param is duplicated error occurs.

Header

Matches the request header. The ALB forwards only requests that contain a specific header to the backend service.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name must match the name of the backend Service configured in spec.rules.
  [{
    "type": "Header",
    "headerConfig": {
      "key": "headername",
      "values": [
        "headervalue1",
        "headervalue2"
      ]
     }
  }]
  • type: The match type of the forwarding condition. Header indicates a match with the request header.

  • headerConfig: The key-value pairs that the request header must contain. If you specify multiple values, they are evaluated by using a logical OR.

For a use case and an example, see Scenario 1: Forward by source IP and request header.

Query string

Matches the query string. The ALB forwards only requests that contain a specific query string to the backend service.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name must match the name of the backend Service configured in spec.rules.
  [{
    "type": "QueryString",
    "queryStringConfig": {
      "values": [
        {
           "key":"querystringkey1",
           "value":"querystringvalue2"
        }
      ]
    }
  }]
  • type: The match type of the forwarding condition. QueryString indicates a match against the query string of the request.

  • queryStringConfig: The key-value pairs of the query string. If you specify multiple key-value pairs, the relationship between them is logical OR.

    The key must be 1 to 100 characters in length. The value must be 1 to 128 characters in length. Both support lowercase letters, visible characters, and the wildcard characters asterisk (*) and question mark (?). Spaces and the following characters are not allowed: #[]{}\|<>&.

For a use case and an example, see Scenario 3: Forward by query string and headers.

Request method

Matches the request method. The ALB forwards only requests that use a specific method to the backend service.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name must match the name of the backend Service configured in spec.rules.
  [{
    "type": "Method",
    "methodConfig": {
      "values": [
        "GET",
        "HEAD"
      ]
    }
  }]
  • type: The match type for the forwarding condition. Method specifies that the match is based on the request method.

  • methodConfig: The request method. The supported methods are GET, POST, PUT, DELETE, HEAD, OPTIONS, and PATCH. If you set multiple request methods, the relationship between them is OR.

For a use case and an example, see Scenario 2: Forward by domain, method, and cookie.

Cookie

Matches the cookie and forwards a request to the backend Service only if it contains the correct cookie.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name需与spec.rules中配置的后端Service名称对应一致。
  [{
    "type": "Cookie",
    "cookieConfig": {
      "values": [
        {
           "key":"cookiekey1",
           "value":"cookievalue2"
        }
      ]
     }
  }]
  • type: The match type of the forwarding condition. Cookie indicates a match based on a cookie.

  • cookieConfig: The cookie key-value pairs. If multiple cookies are set, they are evaluated with a logical OR.

    The key and value must be 1 to 100 characters in length, support lowercase letters, visible characters, and the wildcard characters asterisk (*) and question mark (?), but do not support spaces or the characters #[]{}\|<>&.

For use cases and examples, see Scenario 2: Forwarding based on domain name, request method, and cookie.

Source IP

Matches the source IP of a request. Only requests from client source IPs that are in the list are forwarded to the backend Service.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name需与spec.rules中配置的后端Service名称对应一致。
  [{
    "type": "SourceIp",
    "sourceIpConfig": {
      "values": [
        "192.168.0.0/16",
        "172.16.0.0/16"
      ]
    }
  }]
  • type: The match type for the forwarding condition. SourceIp indicates a match based on the source IP of the request.

  • sourceIpConfig: The request IP address. If you specify multiple IP addresses, they are evaluated with a logical OR.

For usage scenarios and examples, see Scenario 1: Forwarding based on SourceIp and request headers.

Important

The number of SourceIps in a single forwarding condition is limited to 5.

Response header

Matches the response header and performs the forwarding action only on responses that contain the specified header. This setting must be used in conjunction with the alb.ingress.kubernetes.io/rule-direction.<service-name>: Response annotation.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name需与spec.rules中配置的后端Service名称对应一致。
  [{
    "type": "ResponseHeader",
    "responseHeaderConfig": {
      "key": "responseHeader",
      "values": [
        "headervalue1",
        "headervalue2"
      ]
     }
  }]
  • type: The match type of the forwarding condition. ResponseHeader indicates a match with the response header.

  • responseHeaderConfig: The key-value pairs to include in the response header. If you set multiple values, they are evaluated with a logical OR.

For scenarios and examples, see Scenario 7: Modify response headers based on ResponseHeader.

Response status code

Matches the response status code. The service can be accessed only if the correct status code is returned. Note that this must be used in conjunction with the response direction forwarding action and the response direction forwarding rule annotation alb.ingress.kubernetes.io/rule-direction.<service-name>: Response.

alb.ingress.kubernetes.io/conditions.service-name: | # service-name must match the name of the backend Service configured in spec.rules.
  [{
    "type": "ResponseStatusCode",
    "responseStatusCodeConfig": {
      "values": [
        "statuscode1",
        "statuscode2"
      ]
    }
  }]
  • type: The match type of the forwarding condition. ResponseStatusCode indicates a match against the response status code.

  • responseStatusCodeConfig: The specific response status code. If you set multiple response status codes, the relationship between them is a logical OR.

For a use case and an example, see Scenario 8: Modify response headers based on the response status code.

Configure forwarding actions

Scenario 1: Return a fixed response

Console

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Network > Ingresses.

  3. On the Ingresses page, click Create Ingress and use the following parameters.

    Parameter

    Value

    Gateway Type

    ALB Ingress

    Name

    fixed-ingress

    IngressClass

    alb

    Rules

    Delete the default Mappings.

    Custom Forwarding Rules

    Enable Custom Forwarding Rules.

    • Add Condition: Select Path and enter /echo.

    • Action: Select Return Fixed Response.

      • Response Status Code: 503

      • Response Content Type (Optional): text/plain

      • Response Content (Optional): 503 error text

    Keep the default values for other parameters.
  4. When you are finished, click OK.

kubectl

The Ingress in the example below returns an HTTP 503 status code and 503 error text when it receives a request.

Create fixed-response.yaml by copying the following example, and run kubectl apply -f fixed-response.yaml to create an Ingress.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: fixed-ingress
  annotations:
    alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "FixedResponse",
          "FixedResponseConfig": {
              "contentType": "text/plain",
              "httpCode": "503",
              "content": "503 error text"
          }
      }]
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: Prefix
        backend:
          service:
            name: echoserver
            port:
              name: use-annotation # The name of the service port must be set to use-annotation.

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -si ALB_ENDPOINT/echo | grep "HTTP/" 

Expected output:

HTTP/1.1 503 Service Unavailable

Scenario 2: Redirect requests to an HTTPS port

Redirection

The following Ingress example uses an HTTP 301 status code to redirect requests to port 443 of a new domain name.

If the redirected domain name resolves to the ALB instance endpoint, you can use this method to redirect traffic from the HTTP port of the ALB Ingress to the HTTPS port.

Create a redirect.yaml file, copy the following example into it, and run kubectl apply -f redirect.yaml to create an Ingress.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: redirect-ingress
  annotations:
    alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "Redirect",
          "RedirectConfig": {
              "host": "www.alibabacloud.com",
              "path": "/en",
              "port": "443",
              "protocol": "https",
              "query": "_p_lc=1",
              "httpCode": "301"
          }
      }]
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: Prefix
        backend:
          service:
            name: echoserver
            port:
              name: use-annotation # The name of the service port must be set to use-annotation.

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -LIs ALB_ENDPOINT/echo | grep "HTTP"

The expected output indicates that the request is redirected to the new domain name.

HTTP/1.1 301 Moved Permanently
Via: HTTP/1.1 SLB.208
HTTP/2 200 

Redirection for multiple services

The following Ingress example redirects traffic for multiple Services.

  1. Create a Service named echoserver2. For more information, see Create a sample Service.

  2. Create a file named multi-redirect.yaml and copy the following example into it. Run kubectl apply -f multi-redirect.yaml to create an Ingress.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: multi-redirect-ingress
  annotations:
    alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "Redirect",
          "RedirectConfig": {
              "host": "www.alibabacloud.com",
              "path": "/en",
              "port": "443",
              "protocol": "https",
              "query": "_p_lc=1",
              "httpCode": "301"
          }
      }]
    alb.ingress.kubernetes.io/actions.echoserver2: | # The name echoserver2 must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "Redirect",
          "RedirectConfig": {
              "host": "www.alibabacloud.com",
              "path": "/en",
              "port": "443",
              "protocol": "https",
              "query": "_p_lc=1",
              "httpCode": "301"
          }
      }]
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: Prefix
        backend:
          service:
            name: echoserver
            port:
              name: use-annotation # The name of the service port must be set to use-annotation.
      - path: /echo2
        pathType: Prefix
        backend:
          service:
            name: echoserver2
            port:
              name: use-annotation # The name of the service port must be set to use-annotation.

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -LIs ALB_ENDPOINT/echo | grep "HTTP" ;
curl -LIs ALB_ENDPOINT/echo2 | grep "HTTP"

The expected output indicates that requests to both Services are redirected to the new domain name.

HTTP/1.1 301 Moved Permanently
Via: HTTP/1.1 SLB.208
HTTP/2 200
HTTP/1.1 301 Moved Permanently
Via: HTTP/1.1 SLB.208
HTTP/2 200

Scenario 3: Insert a custom request header

The Ingress in the example below inserts source:alibaba into the request header when a request is received.

Create a file named insert-header.yaml with the following example content, and run kubectl apply -f insert-header.yaml to create an Ingress.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: insert-header-ingress
  annotations:
    alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "InsertHeader",
          "InsertHeaderConfig": {
              "key": "source",
              "value": "alibaba",
              "valueType": "UserDefined"
          }
      }]
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: Prefix
        backend:
          service:
            name: echoserver
            port:
              number: 80

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -s ALB_ENDPOINT/echo | grep -A 6 "Request Headers"

Expected output:

Request Headers:
	accept=*/*
	host=alb-jyoefh22rkjeerxmcg.us-west-1.alb.aliyuncsslbintl.com
	remoteip=140.205.***.***
	source=alibaba # Custom request header
	user-agent=curl/8.4.0
	x-forwarded-for=140.205.***.***

Scenario 4: Mirror traffic to a server group

Traffic mirroring allows an ALB Ingress to copy incoming requests and send them to another server group.

  1. Log on to the Application Load Balancer (ALB) console. In the navigation pane on the left, choose ALB > Server Group. On the Server Group page, obtain the ID of the server group.Server Groups

  2. Create a traffic-mirror.yaml file with the following example, and run the kubectl apply -f traffic-mirror.yaml command to create an Ingress.

    The following Ingress example mirrors incoming requests to the server group sgp-2auud2fxj1r46*****.
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: traffic-mirror-ingress
      annotations:
        alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
           [{
               "type": "TrafficMirror",
               "TrafficMirrorConfig": {
                  "TargetType" : "ForwardGroupMirror",
                  "MirrorGroupConfig": {
                      "ServerGroupTuples" : [{
                          "ServerGroupID": "sgp-2auud2fxj1r46*****"
                      }]
                  }
               }
           }]
    spec:
      ingressClassName: alb
      rules:
      - host: demo.domain.ingress.top
        http:
          paths:
          - path: /echo
            pathType: Prefix
            backend:
              service:
                name: echoserver
                port:
                  number: 80

Scenario 5: Forward to multiple backend services

When an ALB Ingress receives a request, it forwards the request to multiple backend Services based on custom weights.

  1. Create a Service named echoserver2. For more information, see Create a sample Service.

  2. Create an Ingress resource.

    Console

    1. Log on to the ACK console. In the left navigation pane, click Clusters.

    2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Network > Ingresses.

    3. On the Ingresses page, click Create Ingress and use the following parameters.

      Parameter

      Value

      Gateway Type

      ALB Ingress

      Name

      forward-ingress

      IngressClass

      alb

      Rules

      Delete the default Mappings.

      Custom forwarding rule

      Enable Custom Forwarding Rules.

      • Add Condition:

        • Domain Name: demo.alb.ingress.top

        • Path: /echo

      • Action: Select Forward To.

        • Service: echoserver

          • Port: 80

        • Service: echoserver2

          • Port: 80

      Keep the default values for other parameters.
    4. When you are finished, click OK.

    kubectl

    Create a forward.yaml file with the following example, and run kubectl apply -f forward.yaml to create an Ingress.

    The following Ingress example forwards incoming requests to the echoserver and echoserver2 Services at a weight ratio of 80:20.
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: forward-ingress
      annotations:
        alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
           [{
               "type": "ForwardGroup",
               "ForwardConfig": {
                 "ServerGroups" : [{
                   "ServiceName": "echoserver",
                   "Weight": 80,
                   "ServicePort": 80
                 },
                 {
                   "ServiceName": "echoserver2",
                   "Weight": 20,
                   "ServicePort": 80
                 }]
               }
           }]
    spec:
      ingressClassName: alb
      rules:
      - host: demo.alb.ingress.top
        http:
          paths:
          - path: /echo
            pathType: Prefix
            backend:
              service:
                name: echoserver
                port:
                  name: use-annotation # This must be set to use-annotation.

Scenario 6: Rewrite request configurations

ALB Ingress lets you use custom forwarding rules to modify the domain name, path, and query parameters of a request. Unlike the rewrite-target annotation, this allows you to modify the domain name. This feature is useful for URL simplification, client-transparent rewrites, and hiding backend implementation details.

Copy the following example to a file named rewrite.yaml and run the kubectl apply -f rewrite.yaml command to create an Ingress.

In the example below, the client's URL https://example.com/api/echo is rewritten to https://example.org/echo.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: rewrite-ingress
  annotations:
    alb.ingress.kubernetes.io/actions.echoserver: | # The name echoserver must match the name of the backend Service that is configured in spec.rules.
       [{
           "type": "Rewrite",
           "RewriteConfig": {
               "host": "example.org", 
               "path": "/echo", 
               "query": "${query}"
           }
       }]
spec:
  ingressClassName: alb
  rules:
  - host: example.com
    http:
      paths:
      - path: /api/echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port: 
              number: 80

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -H "Host:example.com" -s "ALB_ENDPOINT/api/echo?querystring=request" | grep -A 7 "Request Information"

Expected output:

Request Information:
	client_address=::ffff:10.0.2.93
	method=GET
	real path=/echo?querystring=request
	query=querystring=request
	request_version=1.1
	request_scheme=http
	request_uri=http://example.org:8080/echo?querystring=request # The domain name and path are rewritten.

Scenario 7: Modify response headers based on ResponseHeader

The Ingress in the following example modifies the response header. When the response header contains Content-Type: text/plain, the Ingress inserts source: alibaba into the response header.

Create a file named response-header.yaml with the example below, and run kubectl apply -f response-header.yaml to create an Ingress.

Important
  • When you create a forwarding rule for the response direction, you need to set the annotation alb.ingress.kubernetes.io/rule-direction.<service-name> to Response. The default value for this annotation is Request.

  • A forwarding rule for the response direction alone cannot handle request forwarding. The following example also configures a separate Ingress for the request direction.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: response-header-ingress
  annotations:
    alb.ingress.kubernetes.io/rule-direction.echoserver: Response # For response-direction rules, this must be set to Response.
    alb.ingress.kubernetes.io/conditions.echoserver: | # Used with a forwarding condition for the response direction. A custom response header is inserted only for responses that meet the forwarding condition.
     [{
         "type": "ResponseHeader",
         "responseHeaderConfig": {
            "key": "Content-Type",
            "values": [
               "text/plain"
            ]
         }
     }]
    alb.ingress.kubernetes.io/actions.echoserver: | # Inserts a custom response header.
     [{
         "type": "InsertHeader",
         "InsertHeaderConfig": {
             "key": "source",
             "value": "alibaba",
             "valueType": "UserDefined"
         }
     }]
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              name: use-annotation # This must be set to use-annotation.

---
# Ingress for the request direction
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: request-ingress
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              number: 80

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -sI ALB_ENDPOINT/echo | grep "source"

Expected output:

source: alibaba

Scenario 8: Modify response headers by status code

The Ingress in the example below modifies the response header by removing Content-Type from the response header when the response status code is 200 or 300.

Create a response-code.yaml file, copy the following example into it, and run kubectl apply -f response-code.yaml to create an Ingress.

Important
  • When you create a forwarding rule for the response direction, you need to set the annotation alb.ingress.kubernetes.io/rule-direction.<service-name> to Response (this annotation is set to Request by default).

  • A forwarding rule for the response direction alone cannot handle request forwarding. The following example also configures a separate Ingress for the request direction.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    alb.ingress.kubernetes.io/rule-direction.echoserver: Response # For response-direction rules, this must be set to Response.
    alb.ingress.kubernetes.io/conditions.echoserver: | # Used with a forwarding condition for the response direction. The response header is removed only for responses that meet the forwarding condition.
     [{
       "type": "ResponseStatusCode",
       "responseStatusCodeConfig": {
         "values": [
             "200",
             "300"
         ]
       }
     }]
    alb.ingress.kubernetes.io/actions.echoserver: | # Removes a response header.
     [{
         "type": "RemoveHeader",
         "RemoveHeaderConfig": {
             "key": "Content-Type"
         }
     }]
  name: response-code-ingress
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              name: use-annotation # This must be set to use-annotation.
              
---
# Ingress for the request direction
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: request-ingress
spec:
  ingressClassName: alb
  rules:
  - http:
      paths:
      - path: /echo
        pathType: ImplementationSpecific
        backend:
          service:
            name: echoserver
            port:
              number: 80

Verify the results

Replace ALB_ENDPOINT with the endpoint of your ALB instance and run the following command:

curl -sI ALB_ENDPOINT/echo

Expected output:

HTTP/1.1 200 OK
Date: Thu, 29 Jan 2026 09:46:20 GMT
Connection: keep-alive
Vary: Accept-Encoding
# The Content-Type: text/plain header is removed.

Forwarding action reference

Request direction

Forwarding action

Description

Fixed response

Returns a response with fixed content to the client.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
  [{
      "type": "FixedResponse",
      "FixedResponseConfig": {
          "contentType": "text/plain",
          "httpCode": "503",
          "content": "503 error text"
      }
  }]
  • type: The type of the forwarding action. FixedResponse indicates a fixed response.

  • contentType: The content type of the response body.

  • httpCode: The response status code. Supported values are numeric strings in the 2XX, 4XX, or 5XX format.

  • content: The response body.

Important

backend.service.port.name must be set to use-annotation.

For a use case, see Scenario 1: Return a fixed response.

Redirection

Redirects clients to another URL by using an HTTP 3xx status code.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
  [{
      "type": "Redirect",
      "RedirectConfig": {
          "host": "${host}",
          "path": "/test",
          "port": "443",
          "protocol": "https",
          "query": "querystring",
          "httpCode": "301"
      }
  }]
  • type: The type of the forwarding action. A value of Redirect specifies redirection.

  • host: The destination domain name.

  • path: The destination path.

  • port: The destination port.

  • protocol: The protocol for redirection.

  • query: The query string for the redirection.

  • httpCode: The redirect status code. Valid values: 301, 302, 303, 307, or 308.

Important
  • host, path, port, protocol, and query are special parameters. You can configure them to use the values from the original request, but at least one parameter must be set to a non-default value. For the host parameter, for example, setting it to ${host}, leaving it empty (such as "host": ""), or not specifying the parameter indicates that the value from the original request is used.

  • backend.service.port.name must be set to use-annotation.

For a use case, see Scenario 2: Redirect requests to an HTTPS port.

Traffic mirroring

Mirrors requests to a server group by specifying the server group ID.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "TrafficMirror",
          "TrafficMirrorConfig": {
              "TargetType" : "ForwardGroupMirror",
              "MirrorGroupConfig": {
                  "ServerGroupTuples" : [{
                      "ServerGroupID": "sgp-2auud2fxj1r46*****"
                  }]
              }
           }
      }]
  • type: The type of the forwarding action. TrafficMirror specifies that the traffic mirroring feature is configured.

  • TargetType: The target type for mirroring. Currently, the only supported type is ForwardGroupMirror, which mirrors requests to a server group.

  • ServerGroupID: The ID of the traffic mirroring server group.

Important
  • The traffic mirroring action can be combined with forwarding, inserting a request header, removing a request header, and QPS throttling. It is incompatible with rewrite, fixed response, or redirection.

  • Traffic mirroring server groups can only be attached by using ServerGroupID.

For a use case, see Scenario 4: Mirror traffic to a server group.

Forward to multiple backend server groups

You can add multiple server groups to an ALB backend and set their weights to control the traffic distribution ratio. You can add a server group by specifying its ServerGroupID, or create and add a new one by specifying ServiceName+ServicePort.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
       [{
           "type": "ForwardGroup",
           "ForwardConfig": {
             "ServerGroups" : [{
               "ServiceName": "tea-svc",
               "Weight": 30,
               "ServicePort": 80
             },
             {
               "ServiceName": "coffee-svc",
               "Weight": 20,
               "ServicePort": 80
             },
             {
               "ServerGroupID": "sgp-71aexb9y93ypo*****",
               "Weight": 20
             },
             {
               "ServerGroupID": "sgp-slygpbvm2cydo*****",
               "Weight": 30
             }],
             "ServerGroupStickySession": {
              "Enabled": true,
              "Timeout": 80
             }
           }
       }]
  • type: The type of the forwarding action. ForwardGroup specifies that requests are forwarded to multiple backend server groups.

  • ForwardConfig: The specific parameters for the backend forwarding server groups. If multiple server groups are configured, requests are forwarded to the server groups based on their weights.

  • ServerGroupID: The ID of the server group.

  • ServiceName: The name of the service.

  • ServicePort: The port of the service.

  • Weight: The weight for forwarding requests to a server group. The value range is [1, 100].

  • Enabled: Specifies whether to enable session persistence between server groups.

  • Timeout: The session persistence timeout for the server group, in seconds. Value range: [1, 86400].

Important
  • A Standard ALB instance can be attached to a maximum of five server groups or Services.

  • If you attach a server group by specifying both ServerGroupID and ServiceName+ServicePort, ServerGroupID has higher priority.

  • After you enable session persistence between server groups, ALB Ingress forwards requests from the same session to the same backend.

  • backend.service.port.name must be set to use-annotation.

  • You can enable session persistence between server groups. Make sure that session persistence is enabled for all attached server groups.

For a use case, see Scenario 5: Forward to multiple backend services.

Rewrite

This action rewrites the domain name, path, and query string of an incoming request before forwarding it to the backend Service.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
       [{
           "type": "Rewrite",
           "RewriteConfig": {
               "host": "demo.domain.ingress.top",
               "path": "/test",
               "query": "querystring"
           }
       }]
  • type: The type of the forwarding action. Set this parameter to Rewrite to enable rewriting.

  • host: The domain name that the request uses after it is rewritten.

  • path: The path used by the request after it is rewritten.

  • query: The query string of the rewritten request.

Important
  • The rewrite forwarding action and the rewrite-target annotation are mutually exclusive.

  • The rewrite action cannot be used with the fixed response or redirection forwarding actions.

  • host, path, and query are special parameters that can be configured to use their values from the original request, but at least one of them must be set to a non-default value. For example, setting the host parameter to ${host}, leaving it empty ("host": ""), or omitting the parameter entirely all indicate that the value from the original request will be used.

For a use case, see Scenario 6: Rewrite request configurations.

Insert request header

Inserts a header into the request. If a header with the same name already exists, its value is overwritten.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
  [{
      "type": "InsertHeader",
      "InsertHeaderConfig": {
          "key": "key",
          "value": "value",
          "valueType": "UserDefined"
      }
  }]
  • type: The type of the forwarding action. InsertHeader specifies that a request header is inserted.

  • key: The name of the header field to insert.

  • value: The content of the header field to insert.

  • valueType: The content type of the header field.

For a use case, see Scenario 3: Insert a custom request header.

Remove request header

Removes a request header.

alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
     [{
         "type": "RemoveHeader",
         "RemoveHeaderConfig": {
             "key": "key"
         }
     }]
  • type: The type of the forwarding action. Set the value to RemoveHeader to remove a request header.

  • key: The name of the header field to remove.

QPS throttling

Configures an overall request rate limit and a per-client source IP request rate limit.

 annotations:
alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
      [{
          "type": "TrafficLimit",
          "TrafficLimitConfig": {
              "QPS": "1000",
              "QPSPerIp": "100"
          }
      }]
  • type: The type of the forwarding action. A value of TrafficLimit specifies a QPS throttling configuration.

  • QPS: The overall request rate limit, which is the number of requests that can be processed per second. The value range is [1, 1,000,000]. When the request rate exceeds the configured limit, excess new connection requests are rejected, and the client receives an HTTP 503 status code.

  • QPSPerIp: Specifies the request rate limit based on the source IP address of each client. The valid range is [1, 1000000]. When both QPS (overall rate limiting) and QPSPerIp (per-IP rate limiting) are set, the value of QPSPerIp must be less than the value of QPS. When the request rate exceeds the set limit, excess requests are rejected, and the client receives an HTTP 503 status code.

Important
  • The QPS throttling forwarding action must be used together with forwarding to a server group.

  • When the X-Forwarded-For request header contains multiple IP addresses, such as X-Forwarded-For: <client-ip-address>, <proxy1>, <proxy2>, ..., the leftmost address is the real client IP address. To use QPS throttling based on the client source IP address, you must enable the feature to retrieve the real client IP address in the listener settings. This allows the ALB instance to find the real client IP address from the X-Forwarded-For header field. For more information, see XForwardedForConfig.

Response direction

Forwarding action

Description

Insert response header

Inserts a header into the response. If a header with the same name already exists, its value is overwritten.

alb.ingress.kubernetes.io/rule-direction.service-name: Response # For response-direction rules, this must be set to Response.
alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
  [{
      "type": "InsertHeader",
      "InsertHeaderConfig": {
          "key": "key",
          "value": "value",
          "valueType": "UserDefined"
      }
  }]
  • type: The type of the forwarding action. InsertHeader specifies that a response header is inserted.

  • key: The name of the header field to be inserted.

  • value: The content of the header field to be inserted.

  • valueType: The content type of the header field.

For use cases of modifying response headers in the response direction, see Scenario 7: Modify response headers based on ResponseHeader and Scenario 8: Modify response headers by status code.

Remove response header

Removes a response header.

alb.ingress.kubernetes.io/rule-direction.service-name: Response # For response-direction rules, this must be set to Response.
alb.ingress.kubernetes.io/actions.service-name: | # The service-name must match the name of the backend Service that is configured in spec.rules.
     [{
         "type": "RemoveHeader",
         "RemoveHeaderConfig": {
             "key": "key"
         }
     }]

type: The type of the forwarding action. Set to RemoveHeader to remove a response header.

key: The name of the header field to remove.

Quota and limits

  • A forwarding rule for a service can have up to 10 forwarding conditions, including the domain name and Path specified in spec.rules.

  • A forwarding rule supports one terminal forwarding action—such as a redirect, a fixed response, or forwarding to multiple server groups—which can be combined with a rate limiting action.

  • When configuring redirection, fixed response, or forwarding to multiple server groups, backend.service.port.name must be set to use-annotation.

FAQ

How same-type forwarding conditions work

Different routing rule blocks use a logical AND, while values within the same routing rule block use a logical OR. For example:

  • Two different Header rule blocks use a logical AND. The request is forwarded only if the request header matches both headervalue1 and headervalue2.

    
    alb.ingress.kubernetes.io/conditions.service-name: |
      [{
        "type": "Header",
        "headerConfig": {
          "key": "headername",
          "values": [
            "headervalue1"
          ]
         }
      },
      {
        "type": "Header",
        "headerConfig": {
          "key": "headername",
          "values": [
            "headervalue2"
          ]
         }
      }]
  • Values within the same Header rule block use a logical OR. The request header only needs to match either headervalue1 or headervalue2.

    
    alb.ingress.kubernetes.io/conditions.service-name: |
      [{
        "type": "Header",
        "headerConfig": {
          "key": "headername",
          "values": [
            "headervalue1",
            "headervalue2"
          ]
         }
      }]

Why the error The param of Rules.1.RuleConditions.2.HostConfig.Values.2 is duplicated?

If you configure a Host condition in the forwarding conditions and also specify the same domain name in the host field of spec.rules, the Ingress configuration will fail. Please configure the domain name in only one of these locations.