在 knative 服务定义中更改 public url

Changing public url in knative service definition

我目前正在使用 knative,并使用 gloo 和 glooctl 引导了一个简单的安装。开箱即用,一切正常。但是,我只是问自己是否有可能更改生成的 url,服务可用的位置。

我已经更改了域,但我想知道我是否可以 select 一个不包含命名空间的域名,所以 helloworld-go.namespace.mydomain.com 会变成 helloworld-go.mydomain.com

当前的 YAML 定义如下所示:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  labels:
  name: helloworld-go
  namespace: default
spec:
  template:
    spec:
      containers:
      - image: gcr.io/knative-samples/helloworld-go
        env:
        - name: TARGET
          value: Go Sample v1

感谢您的帮助!

这可以通过命名空间 knative-serving 中名为 config-networkConfigMap 进行配置。请参阅 deployment resources:

中的 ConfigMap
apiVersion: v1
data:
  _example: |
    ...
    # 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}
    domainTemplate: "{{.Name}}.{{.Namespace}}.{{.Domain}}"
    ...
kind: ConfigMap
metadata:
  labels:
    serving.knative.dev/release: "v0.8.0"
  name: config-network
  namespace: knative-serving

因此,您的 config-network 应该如下所示:

apiVersion: v1
data:
  domainTemplate: {{ '"{{.Name}}.{{.Domain}}"' }}
kind: ConfigMap
metadata:
  name: config-network
  namespace: knative-serving

您还可以查看并自定义 config-domain 以配置附加到您的服务的域名。

假设您 运行 熟悉 istio 服务网格,knative docs 中有一个示例说明如何使用 Istio Virtual Service 在服务级别完成此操作。