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.
The custom domain name and path do not overwrite the default domain name. Both the default and custom domain names are available.
Procedure
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:160e4dc8Create a Knative Service.
kubectl apply -f ingress-domain.yamlView 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 ksvcExpected output:
NAME URL LATESTCREATED LATESTREADY READY REASON coffee-mydomain http://coffee-mydomain.default.example.com coffee-mydomain-sbwhz coffee-mydomain-sbwhz TrueUse the default domain name to access the Knative Service.
curl -H "Host: coffee-mydomain.default.example.com" http://alb-ijvf32ubve64wz****.cn-shanghai.alb.aliyuncs.comExpected output:
Hello World!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/coffeeExpected output:
Hello World!