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:
-
Knative deployed in your cluster. See Deploy and manage Knative.
-
A registered domain name. See Alibaba Cloud DNS.
-
The kubeconfig file for your cluster, with kubectl connected. See Connect to a cluster using kubectl.
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.
-
Open the ConfigMap for editing.
kubectl edit cm config-domain --namespace knative-serving -
Replace
example.comwith 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. -
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 -
Add a DNS record that maps your custom domain name to the IP address of the Knative gateway.
-
Access the Knative service using the custom domain name.
curl http://helloworld-go.default.mydomain.comExpected 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
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, choose Applications > Knative.
-
On the Knative page, click the Services tab, then click the name of the target service.
-
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.
-
Create a file named
helloworld.knative.top.yaml.vi helloworld.knative.top.yaml -
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 -
Apply the DomainMapping to the cluster.
kubectl apply -f helloworld.knative.top.yamlExpected output:
domainmapping.serving.knative.dev/helloworld.knative.top created -
Verify the DomainMapping.
kubectl get domainmapping helloworld.knative.topExpected output:
NAME URL READY REASON helloworld.knative.top http://helloworld.knative.top True -
Add a DNS record that maps your custom domain name to the IP address of the Knative gateway.
-
Access the Knative service using the custom domain name.
curl http://helloworld.knative.top.mydomain.comExpected 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
-
Configure an HTTPS certificate for your custom domain name.
-
Deploy a gRPC service in Knative to improve network efficiency.