By default, each Knative Service gets a domain name in the {route}.{namespace}.example.com format. This topic explains how to replace example.com with your own domain name.
Choose the approach that fits your use case:
| Approach | When to use |
|---|---|
| Global domain name | Apply the same domain suffix to all Knative Services in the cluster. Configure once in the config-domain ConfigMap. |
| Per-service domain name | Map a specific domain name to a single Knative Service, without affecting other Services. Create a DomainMapping resource, or use the ACS console. |
Prerequisites
Before you begin, ensure that you have:
Knative deployed in the ACS cluster. See Deploy Knative.
A registered domain name. See Alibaba Cloud Domains.
A kubectl client connected to the cluster. See Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Set a global domain name
Setting a global domain name applies the same domain suffix to all Knative Services in the cluster.
Open the
config-domainConfigMap for editing:kubectl edit cm config-domain --namespace knative-servingReplace
example.comwith your domain name and save. The following example usesmydomain.com:apiVersion: v1 kind: ConfigMap metadata: name: config-domain namespace: knative-serving data: mydomain.com: ""Verify that the new domain name 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.comAdd the IP address of the Knative gateway to the resolution settings of the custom domain name in the Alibaba Cloud DNS console.
Access the Knative Service through the custom domain name:
curl http://helloworld-go.default.mydomain.comExpected output:
Hello Knative!
Set a domain name for a single Knative Service
Use this approach to map a specific domain name to one Knative Service, while leaving other Services unaffected.
Use the console
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, find your cluster and click its ID. In the left-side navigation pane, choose Applications > Knative.
On the Knative page, click the Services tab, then click the name of the Service you want to configure.
In the upper-right corner, click Access Control and set the parameters as prompted.
Use kubectl
Create a file named
helloworld.knative.top.yaml:vi helloworld.knative.top.yamlAdd the following content, save, and exit:
apiVersion: serving.knative.dev/v1beta1 kind: DomainMapping metadata: name: <domain-name> namespace: <namespace> spec: ref: name: <service-name> kind: Service apiVersion: serving.knative.dev/v1Where:
<domain-name>: the custom domain name to map to the Knative Service, for example,helloworld.knative.top.mydomain.com.<namespace>: the namespace that contains the Knative Service, for example,default.<service-name>: the name of the Knative Service, for example,helloworld-go.
Apply the manifest:
kubectl apply -f helloworld.knative.top.yamlExpected output:
domainmapping.serving.knative.dev/helloworld.knative.top createdVerify the DomainMapping:
kubectl get domainmapping helloworld.knative.topExpected output:
NAME URL READY REASON helloworld.knative.top http://helloworld.knative.top TrueREADY: Trueconfirms the custom domain name is in effect.Add the IP address of the Knative gateway to the resolution settings of the custom domain name in the Alibaba Cloud DNS console.
Access the Knative Service through the custom domain name:
curl http://helloworld.knative.top.mydomain.comExpected output:
Hello Knative!
What's next
To serve traffic over HTTPS, configure a TLS certificate for your custom domain name. See Configure a certificate to access Knative Services over HTTPS.
To expose a gRPC Service through Knative, see Deploy a gRPC Service in Knative.