How to customize the URL per-service using Knative + Kourier + Operator

41 Views Asked by At

We are using the Knative operator (generated from Helmify) and trying to change the hostname only not the domain (or anything else). Everything is working fine so far.

How can we change the hostname of the service (on a per-service basis) rather than using the service name and leave everything else as-is?

It seems customizing the domain-template does not work but changes are being recognized because I can "break" things like the ingress-class and get the expected failures.

NAMESPACE    NAME    URL                                         LATESTCREATED   LATESTREADY   READY   REASON
serverless   hello   http://hello.serverless.svc.cluster.local   hello-00001     hello-00001   True

We are trying to change the hostname

  • From http://hello.serverless.svc.cluster.local
  • To http://hello-world.serverless.svc.cluster.local

Everything else can be left as-is:

serverless               hello                                                ExternalName
serverless               hello-00001                                          ClusterIP                                         
serverless               hello-00001-private                                  ClusterIP      

Following these instructions https://julz.github.io/docs/v0.20/serving/using-a-custom-domain-per-service/#verify-the-changes until I realized they were not the official/latest docs.

The service being deployed with a custom annotation (note the annotation that is meant to be used for the hostname instead of the service name):

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello
  namespace: serverless
  annotations:
    custom-hostname: hello-world
spec:
  template:
    spec:
      imagePullSecrets:
        - name: docker-registry
      containers:
        - image: docker/sandbox:example
          ports:
            - containerPort: 8080
          env:
            - name: TARGET
              value: "World"

The operator manifest where we try to customize the domain-template ending up with this in the config-network configmap:

apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
  name: knative-serving
  namespace: knative-serving
spec:
  ingress:
    kourier:
      enabled: true
  config:
    network:
      domain-template: |-
        {{if index .Annotations "custom-hostname" -}}
          {{- index .Annotations "custom-hostname" -}}
        {{else -}}
          {{- .Name }}.{{ .Namespace -}}
        {{end -}}
        .{{ .Domain }}
      ingress-class: "kourier.ingress.networking.knative.dev"
0

There are 0 best solutions below