Setting up a custom domain per Service

By default, Knative uses the {route}.{namespace}.{default-domain} fully qualified domain name for the Service, where default-domain is example.com. You are able to change the default-domain following the Setting up a custom domain guide.

This guide documents the process to use a custom FQDN for a Service, like my-service.example.com, created by @bsideup.

There is currently no official process to set up a custom domain per Service. The topic is being discussed here.

Edit using kubectl

  1. Edit the domainTemplate entry on the config-network configuration. You can find more information about it here:

    1. kubectl edit cm config-network --namespace knative-serving

    Replace the domainTemplate with the following (the spaces must be respected):

    1. [...]
    2. data:
    3. [...]
    4. domainTemplate: |-
    5. {{if index .Annotations "custom-hostname" -}}
    6. {{- index .Annotations "custom-hostname" -}}
    7. {{else -}}
    8. {{- .Name}}.{{.Namespace -}}
    9. {{end -}}
    10. .{{.Domain}}

    Save and close your editor.

Edit the Service

  1. In a Service definition, add the custom-hostname annotation:

    1. apiVersion: serving.knative.dev/v1
    2. kind: Service
    3. metadata:
    4. name: hello-world
    5. annotations:
    6. # the Service FQDN will become hello-world.{default-domain}
    7. custom-hostname: hello-world
    8. spec:
    9. [...]

    Apply your changes.

Verify the changes

  1. Verify that the Service was created with the specified hostname:
  1. kubectl get ksvc hello-world
  2. NAME URL LATESTCREATED LATESTREADY READY REASON
  3. hello-world http://hello-world.example.com hello-world-nfqh2 hello-world-nfqh2 True

Feedback

Was this page helpful?

Glad to hear it! Please tell us how we can improve.

Sorry to hear that. Please tell us how we can improve.