How do I change Knative service's default url domain from example.com to e.g. mydomain.com

784 views Asked by At

I have followed this guide https://knative.dev/docs/serving/using-a-custom-domain/ .

using the command

kubectl edit cm config-domain --namespace knative-serving

I replaced the example.com with mydomain.com in the yaml file. I did remove _example wording but not exactly sure if i remove the correct syntax.

After saving it, there seems to be alot of changes to the yaml.

But when i deploy a knative service, the domain url is still using example.com.

This is the current yaml content:

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  mydomain.com: |
    selector:
      app: nonprofit
  svc.cluster.local: |
    selector:
      app: secret
kind: ConfigMap
metadata:
  annotations:
    knative.dev/example-checksum: 74c3fc6a
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"_example":"################################\n#                              #\n#    EXAMPLE CONFIGURATION     #\n#                              #\n################################\n\n# This block is not actually functional configuration,\n# but serves to illustrate the available configuration\n# options and document them in a way that is accessible\n# to users that `kubectl edit` this config map.\n#\n# These sample configuration options may be copied out of\n# this example block and unindented to be in the data block\n# to actually change the configuration.\n\n# Default value for domain.\n# Although it will match all routes, it is the least-specific rule so it\n# will only be used if no other domain matches.\nmydomain.com: |\n\n# These are example settings of domain.\n# example.org will be used for routes having app=nonprofit.\nexample.org: |\n  selector:\n    app: nonprofit\n\n# Routes having the cluster domain suffix (by default 'svc.cluster.local')\n# will not be exposed through Ingress. You can define your own label\n# selector to assign that domain suffix to your Route here, or you can set\n# the label\n#    \"serving.knative.dev/visibility=cluster-local\"\n# to achieve the same effect.  This shows how to make routes having\n# the label app=secret only exposed to the local cluster.\nsvc.cluster.local: |\n  selector:\n    app: secret\n"},"kind":"ConfigMap","metadata":{"annotations":{"knative.dev/example-checksum":"74c3fc6a"},"labels":{"serving.knative.dev/release":"v0.22.0"},"name":"config-domain","namespace":"knative-serving"}}
  creationTimestamp: "2021-05-11T06:43:42Z"
  labels:
    serving.knative.dev/release: v0.22.0
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:mydomain.com: {}
        f:svc.cluster.local: {}
      f:metadata:
        f:annotations:
          .: {}
          f:knative.dev/example-checksum: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
        f:labels:
          .: {}
          f:serving.knative.dev/release: {}
    manager: kubectl.exe
    operation: Update
    time: "2021-05-20T02:15:57Z"
  name: config-domain
  namespace: knative-serving
  resourceVersion: "18217995"
  selfLink: /api/v1/namespaces/knative-serving/configmaps/config-domain
  uid: 8fe4aac5-0413-45c5-8d3e-f7b9ff4e32ed

    
2

There are 2 answers

3
Ville Aikas On

Does the service you deploy have the matching label? As in something like this:

metadata:
  labels:
    app: non-prod

or

metadata:
  labels:
    app: secret

As far many changes to the yaml, there are some auto generated fields, for example the managedFields which decorate the k8s resources. https://kubernetes.io/docs/reference/using-api/server-side-apply/

4
csantanapr On

Be sure when you edit the config map you don’t edit the comments and instead move the indentation

I would recommend to not change example.com and instead add the new new line with key and field.

I would strongly recommend to edit with CLI like this

export KNATIVE_DOMAIN=konk.dev kubectl patch configmap -n knative-serving config-domain -p "{"data": {"$KNATIVE_DOMAIN": ""}}"

You can see how it is used in this tutorial at https://konk.dev