The default domain name of a Knative Service is in the {route}.{namespace}.{default-example.com} format. {default-example.com} is the default suffix. In most cases, the suffix is example.com. This topic describes how to configure a custom domain name to flexibly route traffic. You can modify the ConfigMap of ACS Knative to modify the global domain name that takes effect on all Knative Services. You can also add a DomainMapping to specify a custom domain name for a single Knative Service.
Prerequisites
Knative is deployed in the ACS cluster. For more information, see Deploy Knative.
A domain name is registered. For more information, see Alibaba Cloud Domains.
A kubectl client is connected to the cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Modify the global domain name
If you want all Knative Services deployed in ACS Knative share the same domain name suffix, perform the following steps.
Run the following command to modify the
config-domainConfigMap in theknative-servingnamespace:kubectl edit cm config-domain --namespace knative-servingModify the ConfigMap.
Change the default domain name
example.comin the ConfigMap to your custom domain name and save the ConfigMap. In this example, a custom domain namemydomainis used.apiVersion: v1 kind: ConfigMap metadata: name: config-domain namespace: knative-serving data: mydomain.com: "" # Change example.com to mydomain.com. Replace the default domain name with the actual domain name that you want to use.Run the following command to verify the domain name:
# Replace helloworld-go in the command 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.comThe output indicates that 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.
Run the following command to access the Knative Service through the custom domain name:
curl http://helloworld-go.default.mydomain.comExpected output:
Hello Knative!The output indicates that the Knative Service successfully responds to the request.
Specify a domain name for a single Knative Service
To specify a domain name for a single Knative Service, perform the following steps.
Use the console
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its ID. In the left-side navigation pane of the cluster details page, choose .
On the Knative page, click the Services tab, and then find and click the name of the Service that you want to configure.
In the upper-right corner of the details page, click Access Control, and then set the parameters as prompted.
kubectl
If you want o specify a domain name for a single Knative Service and use the Ingress controller to manage Ingresses, add a DomainMapping.
Run the following command to create a file named
helloworld.knative.top.yaml:vi helloworld.knative.top.yamlOpen the vi editor, add the following YAML content, save the content, and then exit.
apiVersion: serving.knative.dev/v1beta1 kind: DomainMapping metadata: name: helloworld.knative.top.mydomain.com # The domain name of the Knative Service. Replace it with the domain name that you want to use. namespace: default # The namespace to which the Knative Service belongs. spec: ref: name: helloworld-go # The name of the Knative Service. kind: Service apiVersion: serving.knative.dev/v1Run the following command to deploy resources defined in the
helloworld.knative.top.yamlfile to your cluster:kubectl apply -f helloworld.knative.top.yamlExpected output:
domainmapping.serving.knative.dev/helloworld.knative.top createdRun the following command to verify the DomainMapping:
kubectl get domainmapping helloworld.knative.topExpected output:
NAME URL READY REASON helloworld.knative.top http://helloworld.knative.top TrueThe output indicates that 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.
Run the following command to access the Knative Service through the custom domain name:
curl http://helloworld.knative.top.mydomain.comExpected output:
Hello Knative!The output indicates that the Knative Service successfully responds to the request.
References
For more information about how to configure a certificate to access Services over HTTPS through a custom domain name, see Configure a certificate to access Knative Services over HTTPS.
You can deploy a gRPC Service in Knative to improve network efficiency. For more information, see Deploy a gRPC Service in Knative.