All Products
Search
Document Center

Container Service for Kubernetes:Use custom domain names and paths in Knative

Last Updated:Nov 20, 2025

The default domain name for a Knative service is in the format {route}.{namespace}.{default-example.com}. The {default-example.com} part is the default suffix, which is typically `example.com`. To use a custom domain name for more flexible routing, you can follow the steps in this topic. ACK Knative lets you change the global custom domain name for all Knative services using a ConfigMap. You can also use a DomainMapping to set a custom domain name for a single Knative service.

Prerequisites

Configure a global custom domain name

To use the same domain name suffix for all Knative services in ACK Knative without setting a domain name for each service individually, you can follow these steps.

  1. Run the following command to edit the ConfigMap object named config-domain in the knative-serving namespace.

    kubectl edit cm config-domain --namespace knative-serving
  2. Modify the configuration file.

    Change the default domain name from example.com to your custom domain name and save the file. This example sets the custom domain name to mydomain.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: config-domain
      namespace: knative-serving
    data:
      mydomain.com: "" # Replace example.com with mydomain.com. Use your actual service domain name.
  3. Run the following command to check whether the domain name has taken effect.

    # Replace helloworld-go with the name of your Knative service.
    kubectl get route helloworld-go --output jsonpath="{.status.url}" | awk -F/ '{print $3}'

    Expected output:

    helloworld-go.default.mydomain.com

    The output indicates that the custom domain name has taken effect.

  4. Add a DNS record to map the custom domain name to the IP address of the Knative gateway.

  5. Run the following command to access the Knative service using the custom domain name.

    curl http://helloworld-go.default.mydomain.com

    Expected output:

    Hello Knative!

    The output indicates that the custom domain name is configured and the Knative service has successfully responded to the request.

Configure a custom domain name for a single service

To define a specific domain name for a Knative service, you can follow these steps.

Console

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

  2. On the Clusters page, find the cluster you want and click its name. In the left navigation pane, choose Applications > Knative.

  3. On the Knative page, click the Services tab and then click the name of the target service.

  4. On the service details page, click Access Control in the upper-right corner to configure a custom domain name for the service.

kubectl

To define a specific domain name for a Service and use an Ingress controller for flexible routing, you can use a DomainMapping.

  1. Run the following command to create the helloworld.knative.top.yaml file.

    vi helloworld.knative.top.yaml
  2. Add the following YAML content to the file. Then, save and close the file.

    apiVersion: serving.knative.dev/v1beta1
    kind: DomainMapping
    metadata:
      name: helloworld.knative.top.mydomain.com # Set the service domain name. Use your actual service domain name.
      namespace: default # Set the namespace to the one where the service resides.
    spec:
      ref:
        name: helloworld-go # The name of the target service.
        kind: Service
        apiVersion: serving.knative.dev/v1
  3. Run the following command to apply the resources defined in helloworld.knative.top.yaml to the Kubernetes cluster.

    kubectl apply -f helloworld.knative.top.yaml

    Expected output:

    domainmapping.serving.knative.dev/helloworld.knative.top created
  4. Run the following command to verify the DomainMapping.

    kubectl get domainmapping helloworld.knative.top

    Expected output:

    NAME                          URL                                      READY   REASON
    helloworld.knative.top       http://helloworld.knative.top            True

    The output indicates that the custom domain name has taken effect.

  5. Add a DNS record to map the custom domain name to the IP address of the Knative gateway.

  6. Run the following command to access the Knative service using the custom domain name.

    curl http://helloworld.knative.top.mydomain.com

    Expected output:

    Hello Knative!

    The output indicates that the custom domain name is configured and the Knative service has successfully responded to the request.

Configure a custom path for a single service

To define a specific path for a Knative service, you can use the knative.aliyun.com/serving-ingress annotation to specify the custom domain name and path. For example, knative.aliyun.com/serving-ingress: cafe.mydomain.com/coffee specifies the cafe.mydomain.com domain name and the /coffee path.

Single path example:

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

Multiple path example:

Use commas (,) to separate multiple paths.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: coffee-mydomain
  annotations:
    knative.aliyun.com/serving-ingress: cafe.mydomain.com/coffee,cafe.mydomain.com/tea
spec:
  template:
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8

Rewrite the path

The Application Load Balancer (ALB) gateway supports path rewriting. To rewrite the path for a Knative service, you can configure the alb.ingress.kubernetes.io/rewrite-target: annotation. The following code shows an example.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: coffee-mydomain
  annotations:
    knative.aliyun.com/serving-ingress: cafe.mydomain.com/api/coffee
    alb.ingress.kubernetes.io/rewrite-target: /coffee
spec:
  template:
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8

Set a wildcard domain name

To define a wildcard domain name for a Knative service, you can set the value of the knative.aliyun.com/serving-ingress annotation to /. For example, knative.aliyun.com/serving-ingress: / specifies a wildcard domain name. The following code shows an example.

Only ALB gateways are supported.

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

References