Add a custom route for Knative
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
-
kubectlconfigured to connect to your ACK cluster
Add a custom domain name and path
-
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 -
Apply the manifest:
kubectl apply -f ingress-domain.yaml -
Verify the Service is ready.
READYmust showTrueandURLshows the default domain:kubectl get ksvcExpected output:
NAME URL LATESTCREATED LATESTREADY READY REASON coffee-mydomain http://coffee-mydomain.default.example.com coffee-mydomain-sbwhz coffee-mydomain-sbwhz True -
Test access via the default domain. The
-H "Host:"flag bypasses DNS, letting you verify routing before DNS is configured. Replacealb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.comwith your ALB endpoint:curl -H "Host: coffee-mydomain.default.example.com" http://alb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.comExpected output:
Hello World! -
Test access via the custom domain and path:
curl -H "Host: cafe.mydomain.com" http://alb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.com/coffeeExpected output:
Hello World!
Next steps
-
Configure a custom domain name — change the primary domain for all Knative Services