您可以使用全局网络设置自定义 Tanzu Kubernetes Grid,包括默认容器网络接口 (CNI)、代理服务器和 TLS 证书。对 Tanzu Kubernetes Grid 进行的配置是全局性的,会影响已置备的所有 TKG 集群。

TkgServiceConfiguration

TkgServiceConfiguration 规范提供了用于配置在 主管 中运行的 Tanzu Kubernetes Grid 实例的字段。
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
配置 Tanzu Kubernetes Grid 是一项全局操作。您对 TkgServiceConfiguration 规范所做的所有更改将应用到该 TKG 实例置备的所有 TKG 集群。如果手动或通过升级启动滚动更新,则会更新现有 TKG 集群。
注: 要配置 TkgServiceConfiguration,需要具有 vSphere 管理员特权。如果已创建 TKG 集群操作员角色,则无法使用该角色。

注释的 TkgServiceConfiguration 规范

以下 YAML 列出并介绍了每个 TkgServiceConfiguration 规范参数的可配置字段。
apiVersion: run.tanzu.vmware.com/v1alpha3
kind: TkgServiceConfiguration
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 Supervisor Cluster Pod, Egress, Ingress CIDRs
    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

代理服务器配置

如果配置了代理服务器,则集群将使用该代理服务器传输出站 HTTP 和 HTTPS 流量。为 TKG 集群配置代理服务器时,请牢记以下要求。
  • 必需的 proxy 参数为 httpProxyhttpsProxynoProxy。如果添加 proxy 部分,则所有三个字段均为必填字段。
  • 您可以使用 HTTP 连接到代理服务器。不支持 HTTPS 连接。
  • 工作负载网络获取所需的 spec.proxy.noProxy 值。不得通过将命名空间网络(以前称为“Pod CIDR”)、输入(以前称为“输入 CIDR”)和输出(以前称为“输出 CIDR”)包含在 noProxy 字段中对其进行代理。请参阅下面的示例图像。
  • 无需在 noProxy 字段中包括“服务 CIDR”。TKG 集群不与此子网交互。
  • 无需在 noProxy 字段中包括 TKG 集群规范的 network.services.cidrBlocksnetwork.pods.cidrBlocks 值。系统不会自动代理这些子网。
  • 无需在 noProxy 字段中包括 localhost127.0.0.1。系统不会自动代理端点。

何时使用全局或每个集群配置选项

TkgServiceConfiguration 是一个全局规范,将会影响 Tanzu Kubernetes Grid 实例置备的所有 Tanzu Kubernetes 集群。

在编辑 TkgServiceConfiguration 规范之前,请注意可能满足您的用例(而不是全局配置)的每个集群备用方案。
注: 如果在 TkgServiceConfiguration 上配置了全局代理,则会在集群初始部署后,将该代理信息传播到集群清单中。仅当创建集群时未显示代理配置字段的情况下,才会向集群清单中添加全局代理配置。换句话说,每个集群的配置优先,并将覆盖全局代理配置。

在编辑 TkgServiceConfiguration 规范之前,请注意在全局级别应用设置的影响。

字段 已应用 添加/更改时对现有集群的影响 创建集群时的每个集群替代 更新集群时的每个集群替代
defaultCNI 全局 是,可在创建集群时替代全局设置 否,无法更改现有集群的 CNI;如果在创建集群时使用全局设置的默认 CNI,则无法更改
proxy 全局 是,可在创建集群时替代全局设置 是,对于 U2+,可在更新集群时替代全局设置
trust 全局 是,可在创建集群时替代全局设置 是,对于 U2+,可在更新集群时替代全局设置

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

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}}}}"