This topic describes how to use a custom domain name in the Knative Serving component.

Prerequisites

Background information

The Knative Serving route uses example.com as the default domain name. You can also define a custom domain name in the format of {route}.{namespace}.{default-domain}.

Use kubectl to modify a domain name

The following example describes how to modify a domain name to a custom one in the knative-serving namespace.

  1. Connect to Kubernetes clusters through kubectl
  2. Run the following command to modify the config-domain file of the domain name.
    kubectl edit cm config-domain --namespace knative-serving
  3. Modify the configuration file.
    Use a custom domain name, for example, mydomain.com, to replace example.com, and save the settings.
    apiVersion: v1
    data:
      mydomain.com: ""
    kind: ConfigMap
    [...]

Deploy an application

If you have deployed an application, Knative automatically updates all services and routes based on the modification to the domain name configuration.

  1. Deploy an application. For more information, see Use Knative to deploy a Hello World application.
    In this example, deploy an application named helloworld-go.
  2. View the deployment result.
    • In Knative V0.7, run the following command to view the domain name:
      kubectl get route ${SVC_NAME} --output jsonpath="{.status.url}"| awk -F/ '{print $3}'`
    • In Knative V0.6, run the following command to view the domain name:
      kubectl get route helloworld-go --output jsonpath="{.status.domain}"
    If the following result is returned, the custom domain name takes effect:
    helloworld-go.default.mydomain.com

Publish a domain name

  1. Log on to the Container Service console.
  2. In the left-side navigation pane under Container Service - Kubernetes, choose Knative (Preview) > Services. The Knative Services page appears.
  3. Select the target cluster and namespace to view the access gateway of the target application.
  4. Add the corresponding domain name resolution record to resolve the Knative gateway.

Result

Run the following command to view the execution result:
curl http://helloworld-go.default.mydomain.com