在基建服务定义中更改公共URL

时间:2019-09-25 20:36:09

标签: kubernetes knative knative-serving

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

我已经更改了域,但是我想知道是否可以在不包含名称空间的情况下选择域名,所以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

谢谢您的帮助!

1 个答案:

答案 0 :(得分:3)

这可以通过名称空间file/file.php?id=中名为ConfigMap的{​​{1}}进行配置。请参见Azure Cosmos DB service quotas中的ConfigMap:

config-network

因此,您的knative-serving应该如下所示:

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,以配置附加到您的服务的域名。