您可以为使用 v1alpha3 API 置备的 TKG 集群自定义 TKG 服务配置,包括容器网络接口 (CNI)、代理服务器和 TLS 证书。

关于自定义 TkgServiceConfiguration

您可以通过编辑 TkgServiceConfiguration 来为 Tanzu Kubernetes 集群配置全局设置。通过此配置可以设置默认 CNI,添加全局代理服务器以及添加一个或多个受信任的 TLS 证书。

小心: 自定义 TkgServiceConfiguration 是一项全局操作。对 TkgServiceConfiguration 对象所做的任何更改均将应用于该服务置备的所有 TKG 集群。如果手动或通过升级启动了滚动更新,则集群将由更改后的服务规范进行更新。
注: TkgServiceConfiguration 自定义适用于使用 v1alpha3 API 置备的 Tanzu Kubernetes 集群。它不适用于使用 v1beta1 API 置备的集群。

TkgServiceConfiguration 规范

TkgServiceConfiguration 规范提供了用于配置 Tanzu Kubernetes Grid 实例的字段。
重要说明: 有效密钥名称只能包含字母数字字符、短划线(如 key-name)、下划线(如 KEY_NAME)或点(如 key.name)。不能在密钥名称中使用空格。
apiVersion: run.tanzu.vmware.com/v1alpha3
kind: TkgServiceConfiguration
metadata:
  name: tkg-service-configuration-spec
spec:
  defaultCNI: string
  proxy:
    httpProxy: string
    httpsProxy: string
    noProxy: [string]
  trust:
    additionalTrustedCAs:
      - name: string
        data: string
  defaultNodeDrainTimeout: time

带注释的 TkgServiceConfiguration 规范

以下 YAML 列出并介绍了每个 TkgServiceConfiguration 规范参数的可配置字段。
apiVersion: run.tanzu.vmware.com/v1alpha3
kind: TkgServiceConfiguration
#valid config key must consist of alphanumeric characters, '-', '_' or '.'
metadata:
  name: tkg-service-configuration-spec
spec:
  #defaultCNI is the default CNI for all Tanzu Kubernetes 
  #clusters to use unless overridden on a per-cluster basis 
  #supported values are antrea, calico, antrea-nsx-routed
  #defaults to antrea
  defaultCNI: string
  #proxy configures a proxy server to be used inside all 
  #clusters provisioned by this TKGS instance
  #if implemented all fields are required
  #if omitted no proxy is configured 
  proxy:
    #httpProxy is the proxy URI for HTTP connections 
    #to endpionts outside the clusters
    #takes the form http://<user>:<pwd>@<ip>:<port>
    httpProxy: string
    #httpsProxy is the proxy URI for HTTPS connections 
    #to endpoints outside the clusters
    #takes the frorm http://<user>:<pwd>@<ip>:<port>
    httpsProxy: string
    #noProxy is the list of destination domain names, domains, 
    #IP addresses, and other network CIDRs to exclude from proxying
    #must include from Workload Network: [Namespace Netowrk, Ingress, Egress]
    noProxy: [string]
  #trust configures additional trusted certificates 
  #for the clusters provisioned by this TKGS instance
  #if omitted no additional certificate is configured
  trust: 
    #additionalTrustedCAs are additional trusted certificates 
    #can be additional CAs or end certificates
    additionalTrustedCAs:
      #name is the name of the additional trusted certificate
      #must match the name used in the filename
      - name: string
        #data holds the contents of the additional trusted cert 
        #PEM Public Certificate data encoded as a base64 string
        data: string
  #defaultNodeDrainTimeout is the total amount of time the
  #controller spends draining a node; default is undefined
  #which is the value of 0, meaning the node is drained 
  #without any time limitations; note that `nodeDrainTimeout` 
  #is different from `kubectl drain --timeout`
  defaultNodeDrainTimeout: time
图 1. 所需的 noProxy 值
所需的 noProxy 值
注: 如果在 TkgServiceConfiguration 上配置了全局代理,则会在集群初始部署后,将该代理信息传播到集群清单中。仅当创建集群时未显示代理配置字段的情况下,才会向集群清单中添加全局代理配置。换句话说,每个集群的配置优先,并将覆盖全局代理配置。

示例 TkgServiceConfiguration 规范

以下 YAML 列出并介绍了每个 TkgServiceConfiguration 规范参数的可配置字段。

apiVersion: run.tanzu.vmware.com/v1alpha3
kind: TkgServiceConfiguration
metadata:
  name: tkgserviceconfiguration_example
spec:
  defaultCNI: calico
  proxy:
    #supported format is `http://<user>:<pwd>@<ip>:<port>`
    httpProxy: http://admin:[email protected]:80
    httpsProxy: http://admin:[email protected]:80
    #noProxy vaulues are from Workload Network: [Namespace Network, Ingress, Egress]
    noProxy: [10.246.0.0/16,192.168.144.0/20,192.168.128.0/20]
  trust: 
    additionalTrustedCAs:
      #name is the name of the public cert
      - name: CompanyInternalCA-1
      #data is base64-encoded string of a PEM encoded public cert
        data: LS0tLS1C...LS0tCg==
        #where "..." is the middle section of the long base64 string
      - name: CompanyInternalCA-2
        data: MTLtMT1C...MT0tPg==        
  defaultNodeDrainTimeout: 0

编辑 TkgServiceConfiguration

请参考以下过程编辑 TkgServiceConfiguration 规范。
  1. 配置 Kubectl 编辑。请参见为 Kubectl 配置文本编辑器
  2. 主管 进行身份验证。
    kubectl vsphere login --server=SVC-IP-ADDRESS --vsphere-username USERNAME
  3. 将上下文切换到目标 vSphere 命名空间
    kubectl config use-context vSphere-Namespace
  4. 获取 TkgServiceConfiguration 规范。
    kubectl get tkgserviceconfigurations
  5. 加载 TkgServiceConfiguration 规范进行编辑。
    kubectl edit tkgserviceconfigurations tkg-service-configuration

    系统将在您的 KUBE_EDITOR 或 EDITOR 环境变量定义的默认文本编辑器中打开 tkg-service-configuration 规范。

  6. 根据您的要求编辑 TkgServiceConfiguration
  7. 要应用更改,请在文本编辑器中保存该文件。要取消,请在不保存的情况下关闭编辑器。

    在文本编辑器中保存更改时,kubectl 会更新 tkg-service-configuration 服务规范。

  8. 验证 TkgServiceConfiguration 规范是否已更新。
    kubectl get tkgserviceconfigurations

将全局配置更改传播到现有集群

TkgServiceConfiguration 中以全局级别进行的设置可能不会自动传播到现有集群。例如,如果在 TkgServiceConfiguration 中对 proxytrust 设置进行更改,则此类更改可能不会影响已置备的集群。

要手动将全局更改传播到现有集群,必须修补 Tanzu Kubernetes 集群,以使集群继承对 TkgServiceConfiguration 所做的更改。

例如:
kubectl patch tkc <CLUSTER_NAME> -n <NAMESPACE> --type merge -p "{\"spec\":{\"settings\":{\"network\":{\"proxy\": null}}}}"
kubectl patch tkc <CLUSTER_NAME> -n <NAMESPACE> --type merge -p "{\"spec\":{\"settings\":{\"network\":{\"trust\": null}}}}"