Knative: Operator’s Handbook

Overriding domain naming format

If you don't like how Knative default domain naming work, you can customize it. This is an escape hatch if the default naming format doesn't work for you (for reasons like making wildcard TLS certificates work).

Edit the config-network ConfigMap in knative-serving namespace:

$ kubectl edit configmap config-network --namespace=knative-serving

Under the data: key, add this new key:

data:
  domainTemplate: "{{.Name}}.{{.Namespace}}.{{.Domain}}"

Note: Make sure your custom template doesn't result in domain name collisions (e.g. for services with the same name but in different namespaces).

Read details (from the ConfigMap)
# domainTemplate specifies the golang text template string to use
# when constructing the Knative service's DNS name. The default
# value is "{{.Name}}.{{.Namespace}}.{{.Domain}}". And those three
# values (Name, Namespace, Domain) are the only variables defined.
#
# Changing this value might be necessary when the extra levels in
# the domain name generated is problematic for wildcard certificates
# that only support a single level of domain name added to the
# certificate's domain. In those cases you might consider using a value
# of "{{.Name}}-{{.Namespace}}.{{.Domain}}", or removing the Namespace
# entirely from the template. When choosing a new value be thoughtful
# of the potential for conflicts - for example, when users choose to use
# characters such as `-` in their service, or namespace, names.
# {{.Annotations}} can be used for any customization in the go template if needed.
# We strongly recommend keeping namespace part of the template to avoid domain name clashes
# Example '{{.Name}}-{{.Namespace}}.{{ index .Annotations "sub"}}.{{.Domain}}'
# and you have an annotation {"sub":"foo"}, then the generated template would be {Name}-{Namespace}.foo.{Domain}