Changing the default domain

By default, Knative Serving routes use example.com as the default domain. The fully qualified domain name for a route by default is {route}.{namespace}.{default-domain}.

To change the {default-domain} value there are a few steps involved:

Tip

Customizing a domain template affects your cluster globally. If you want to customize the domain of each service, use DomainMapping instead. For more information, see Configuring custom domains.

Edit using kubectl

  1. Edit the domain configuration config-map to replace example.com with your own domain, for example mydomain.com:

    1. kubectl edit configmap config-domain -n knative-serving

    This command opens your default text editor and allows you to edit the ConfigMap.

    1. apiVersion: v1
    2. data:
    3. _example: |
    4. ################################
    5. # #
    6. # EXAMPLE CONFIGURATION #
    7. # #
    8. ################################
    9. # ...
    10. example.com: |
    11. kind: ConfigMap
  2. Edit the file to replace example.com with the domain you want to use, then remove the _example key and save your changes. In this example, mydomain.com is configured as the domain for all routes:

    1. apiVersion: v1
    2. data:
    3. mydomain.com: ""
    4. kind: ConfigMap
    5. [...]

Apply from a file

You can also apply an updated domain configuration:

  1. Create a YAML file using the following template:

    1. apiVersion: v1
    2. kind: ConfigMap
    3. metadata:
    4. name: config-domain
    5. namespace: knative-serving
    6. data:
    7. # These are example settings of domain.
    8. # example.org will be used for routes having app=prod.
    9. example.org: |
    10. selector:
    11. app: prod
    12. # Default value for domain, for routes that does not have app=prod labels.
    13. # Although it will match all routes, it is the least-specific rule so it
    14. # will only be used if no other domain matches.
    15. example.com: ""

    Replace example.org and example.com with the new domain you want to use.

  2. Apply the YAML file by running the command:

    1. kubectl apply -f <filename>.yaml

    Where <filename> is the name of the file you created in the previous step.

Deploy an application

If you have an existing deployment, Knative reconciles the change made to the ConfigMap, and automatically updates the host name for all of the deployed Services and Routes.

Deploy an app (for example, helloworld-go), to your cluster as normal. You can retrieve the URL in Knative Route “helloworld-go” with the following command:

  1. kubectl get route helloworld-go --output jsonpath="{.status.url}"

You should see the full customized domain: helloworld-go.default.mydomain.com.

Verify the domain using temporary DNS

If you are using curl to access the sample applications, or your own Knative app, there is a temporary approach to verify the customized domain.

Instruct curl to connect to the External IP or CNAME defined by the networking layer mentioned in Install a networking layer, and use the -H "Host:" command-line option to specify the Knative application’s host name. For example, if the networking layer defines your External IP and port to be http://192.168.39.228:32198 and you wish to access the helloworld-go application mentioned earlier, use:

  1. curl -H "Host: helloworld-go.default.mydomain.com" http://192.168.39.228:32198

In the case of the provided helloworld-go sample application, using the default configuration, the output is:

  1. Hello Go Sample v1!

Refer to the Publish your Domain method for a permanent solution.

Publish your Domain

Follow these steps to make your domain publicly accessible:

Update your DNS records

To publish your domain, you need to update your DNS provider to point to the IP address for your service ingress.

  • Create a wildcard record for the namespace and custom domain to the ingress IP Address, which would enable hostnames for multiple services in the same namespace to work without creating additional DNS entries.
  1. *.default.mydomain.com 59 IN A 35.237.28.44
  • Create an A record to point from the fully qualified domain name to the IP address of your Knative gateway. This step needs to be done for each Knative Service or Route created.
  1. helloworld-go.default.mydomain.com 59 IN A 35.237.28.44

If you are using Google Cloud DNS, you can find step-by-step instructions in the Cloud DNS quickstart.

Once the domain update has propagated, you can access your app using the fully qualified domain name of the deployed route, for example http://helloworld-go.default.mydomain.com