Add a custom route for Knative

Updated at:

Map a custom domain and path to a Knative Service while keeping the default domain active.

Add a custom route to a single Knative Service with the knative.aliyun.com/serving-ingress annotation. To change the primary domain for all Knative Services, configure a custom domain name.

How it works

Each Knative Service gets a default domain name in the format {ksvc-name}.{namespace}.{knative-default-domain}. The primary domain defaults to example.com, so a Service named coffee in the default namespace gets coffee.default.example.com.

To add a second domain name and path, set the knative.aliyun.com/serving-ingress annotation on the Service. For example, knative.aliyun.com/serving-ingress: cafe.mydomain.com/coffee routes cafe.mydomain.com/coffee to the Service. The custom domain does not replace the default domain — both remain active.

Prerequisites

  • A running Knative Service in an ACK cluster

  • kubectl configured to connect to your ACK cluster

Add a custom domain name and path

  1. Create a file named ingress-domain.yaml:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: coffee-mydomain
      annotations:
        knative.aliyun.com/serving-ingress: cafe.mydomain.com/coffee
    spec:
      template:
        spec:
          containers:
            - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8
  2. Apply the manifest:

    kubectl apply -f ingress-domain.yaml
  3. Verify the Service is ready. READY must show True and URL shows the default domain:

    kubectl get ksvc

    Expected output:

    NAME              URL                                          LATESTCREATED           LATESTREADY             READY   REASON
    coffee-mydomain   http://coffee-mydomain.default.example.com   coffee-mydomain-sbwhz   coffee-mydomain-sbwhz   True
  4. Test access via the default domain. The -H "Host:" flag bypasses DNS, letting you verify routing before DNS is configured. Replace alb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.com with your ALB endpoint:

    curl -H "Host: coffee-mydomain.default.example.com" http://alb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.com

    Expected output:

    Hello World!
  5. Test access via the custom domain and path:

    curl -H "Host: cafe.mydomain.com" http://alb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.com/coffee

    Expected output:

    Hello World!

Next steps