All Products
Search
Document Center

Container Service for Kubernetes:Add a custom route for Knative

Last Updated:Apr 17, 2025

This topic describes how to add a custom domain name and a path for a Knative Service, and access the Knative Service through the custom domain name and path.

Configure a custom domain name

Knative has a default primary domain name. Each Knative Service has a unique domain name that is generated based on the primary domain name of Knative, the namespace, and the Service name. The format of a domain name is {ksvc-name}.{namespace}.{knative-default-domain}. The default primary domain name of Knative is example.com. If a Knative Service named coffee is deployed in the default namespace, the default domain name of the Knative Service is coffee.default.example.com. You can modify the default primary domain name example.com of Knative. For more information, see Configure a custom domain name.

If you want to configure multiple domain names for a Knative Service, specify custom domain names and paths in the knative.aliyun.com/serving-ingress annotation. For example, knative.aliyun.com/serving-ingress: cafe.mydomain.com/coffee specifies the cafe.mydomain.com domain name and the /coffee path.

Note

The custom domain name and path do not overwrite the default domain name. Both the default and custom domain names are available.

Procedure

  1. Copy the following content to the ingress-domain.yaml file:

    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. Create a Knative Service.

    kubectl apply -f ingress-domain.yaml
  3. View information about the Knative Service.

    The output shows that the default domain name of the Knative Service is coffee-mydomain.default.example.com.

    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. Use the default domain name to access the Knative Service.

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

    Expected output:

    Hello World!
  5. Use the custom domain name and path to access the Knative Service.

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

    Expected output:

    Hello World!