All Products
Search
Document Center

Container Service for Kubernetes:Use custom domain names in Knative

Last Updated:Mar 26, 2026

By default, ACK Knative assigns domain names in the format {route}.{namespace}.example.com. To use your own domain, ACK Knative supports four configuration approaches depending on your use case.

Configuration Use when Method
Global domain suffix Same domain suffix for all services in the cluster Edit config-domain ConfigMap
Single-service domain Specific domain for one service Console or DomainMapping resource
Custom path Route traffic to a specific path on a domain knative.aliyun.com/serving-ingress annotation
Wildcard domain Match all subdomains (ALB gateway only) knative.aliyun.com/serving-ingress: "/"

Prerequisites

Before you begin, ensure that you have:

Set a global custom domain name

Edit the config-domain ConfigMap in the knative-serving namespace to apply the same domain suffix to all Knative services at once.

  1. Open the ConfigMap for editing.

    kubectl edit cm config-domain --namespace knative-serving
  2. Replace example.com with your domain name, then save and close the file.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: config-domain
      namespace: knative-serving
    data:
      mydomain.com: "" # Replace with your actual domain name.
  3. Verify the change 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
  4. Add a DNS record that maps your custom domain name to the IP address of the Knative gateway.

  5. Access the Knative service using the custom domain name.

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

    Expected output:

    Hello Knative!

Set a custom domain name for a single service

To bind a specific domain name to one Knative service, use the ACK console or a DomainMapping 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, choose Applications > Knative.

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

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

kubectl

Use a DomainMapping resource to map a specific domain name to a Knative service.

  1. Create a file named helloworld.knative.top.yaml.

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

    apiVersion: serving.knative.dev/v1beta1
    kind: DomainMapping
    metadata:
      name: helloworld.knative.top.mydomain.com # Set to your actual domain name.
      namespace: default # Set to the namespace where the target service resides.
    spec:
      ref:
        name: helloworld-go # The name of the target Knative service.
        kind: Service
        apiVersion: serving.knative.dev/v1
  3. Apply the DomainMapping to the cluster.

    kubectl apply -f helloworld.knative.top.yaml

    Expected output:

    domainmapping.serving.knative.dev/helloworld.knative.top created
  4. Verify the DomainMapping.

    kubectl get domainmapping helloworld.knative.top

    Expected output:

    NAME                     URL                             READY   REASON
    helloworld.knative.top   http://helloworld.knative.top   True
  5. Add a DNS record that maps your custom domain name to the IP address of the Knative gateway.

  6. Access the Knative service using the custom domain name.

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

    Expected output:

    Hello Knative!

Set a custom path for a single service

Use the knative.aliyun.com/serving-ingress annotation to route traffic to a specific path on a custom domain. For example, knative.aliyun.com/serving-ingress: cafe.mydomain.com/coffee routes traffic to the /coffee path on cafe.mydomain.com.

To route traffic from multiple paths to the same service, separate the paths with commas.

Single path:

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 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. Add the alb.ingress.kubernetes.io/rewrite-target annotation alongside knative.aliyun.com/serving-ingress to rewrite the incoming path before it reaches your service.

The following example routes traffic from /api/coffee on the Ingress to /coffee on the service:

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 match all subdomains under your custom domain, set the knative.aliyun.com/serving-ingress annotation to /.

Wildcard domain names are only supported with ALB gateways.
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

What's next