The default domain name format for a Knative Service is {route}.{namespace}.{default-example.com}, where {default-example.com} is the default domain suffix, which is typically example.com. ACS support custom domains for more flexible route configuration.
You can customize domains in two ways:
Customize the domain globally for all Knative Services by modifying the ConfigMap.
You can use the
knative.aliyun.com/serving-ingressannotation to quickly configure a custom domain for a specific Knative Service.
Prerequisites
You have deployed Knative in the ACS cluster.
You have registered a domain name. For more information, seeAlibaba Cloud Domains.
Configure a global custom domain
To apply a common domain suffix to all Knative Services, follow these steps.
Run the following command to edit the
config-domainConfigMap object in theknative-servingnamespace.kubectl edit cm config-domain --namespace knative-servingModify the configuration file.
Change the default domain name
example.comin the configuration file to a custom domain and save the configuration. In this example, the custom domain is set tomydomain.apiVersion: v1 kind: ConfigMap metadata: name: config-domain namespace: knative-serving data: mydomain.com: "" # Replace example.com with mydomain.com. In a real-world scenario, replace this with your own service domain.Run the following command to verify that the new domain is applied:
# 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.comThis output confirms the custom domain is applied.
Update the DNS records for your domain to point to the IP address of the Knative gateway. For more information, seeAdd a DNS record.
Run the following command to access the Knative Service with the custom domain:
curl http://helloworld-go.default.mydomain.comExpected output:
Hello Knative!This output confirms that the Knative Service is accessible via the custom domain.
Configure a per-service domain and path
To define a specific domain name and path for a Knative Service, you can use the knative.aliyun.com/serving-ingress annotation to directly specify a 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.
Custom domain example
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: coffee-mydomain
annotations:
knative.aliyun.com/serving-ingress: cafe.mydomain.com
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8Wildcard domain example
Separate multiple domains with a comma.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: coffee-mydomain
annotations:
knative.aliyun.com/serving-ingress: "*.mydomain.com"
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8Single 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:160e4dc8Multiple paths example
Separate multiple paths with a comma.
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:160e4dc8Rewrite a path
The ALB gateway supports path rewriting. You can rewrite the Path for a Knative Service by configuring the alb.ingress.kubernetes.io/rewrite-target: annotation. The following is a code 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:160e4dc8Configure a universal wildcard domain
To define a wildcard domain for a Knative Service, set the value of the Annotationknative.aliyun.com/serving-ingress to /. For example, knative.aliyun.com/serving-ingress: / indicates a full wildcard domain. The following is 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