請參閱此範例,佈建具有預設設定的 v1beta1 叢集。

v1beta1 範例:預設叢集

以下範例 YAML 使用 v1beta1 API 在預設 ClusterClass 的基礎上建立預設叢集。

此範例表示使用 v1beta1 API 建立叢集所需的最低組態。此範例針對每個欄位新增了註解說明。如需詳細資訊,請參閱來源代碼

請注意有關此範例的以下事項:
  • v1alpha3 API 不同,v1beta1 API 要求指定 clusterNetwork。叢集類型沒有預設的網路設定。
  • 預設 ClusterClass 為 tanzukubernetescluster,詳細資訊請參閱:叢集 v1beta1 API
  • 可以使用 variables 自訂叢集,每個變數都是一個名稱-值配對。必須至少將虛擬機器類別和儲存區類別指定為變數,如此範例中所示。
  • 儘管在技術上是可選操作,但該範例還包含一個 defaultStorageClass 變數,因為許多工作負載 (包括 Tanzu 套件和 Helm 圖表) 都要求使用預設儲存區類別佈建叢集。
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
#define the cluster
metadata:
  #user-defined name of the cluster; string
  name: cluster-default
  #kubernetes namespace for the cluster; string
  namespace: tkg-cluster-ns
#define the desired state of cluster
spec:
  #specify the cluster network; required, there is no default
  clusterNetwork:
    #network ranges from which service VIPs are allocated
    services:
      #ranges of network addresses; string array
      #CAUTION: must not overlap with Supervisor
      cidrBlocks: ["198.51.100.0/12"]
    #network ranges from which Pod networks are allocated
    pods:
      #ranges of network addresses; string array
      #CAUTION: must not overlap with Supervisor
      cidrBlocks: ["192.0.2.0/16"]
    #domain name for services; string
    serviceDomain: "cluster.local"
  #specify the topology for the cluster
  topology:
    #name of the ClusterClass object to derive the topology
    class: tanzukubernetescluster
    #kubernetes version of the cluster; format is TKR NAME
    version: v1.26.13---vmware.1-fips.1-tkg.3
    #describe the cluster control plane
    controlPlane:
      #number of control plane nodes
      #integer value 1 or 3
      #NOTE: Production clusters require 3 control plane nodes
      replicas: 3
    #describe the cluster worker nodes
    workers:
      #specifies parameters for a set of worker nodes in the topology
      machineDeployments:
        #node pool class used to create the set of worker nodes
        - class: node-pool
          #user-defined name of the node pool; string
          name: node-pool-1
          #number of worker nodes in this pool; integer 0 or more
          replicas: 3
    #customize the cluster
    variables:
      #virtual machine class type and size for cluster nodes
      - name: vmClass
        value: guaranteed-medium
      #persistent storage class for cluster nodes
      - name: storageClass
        value: tkg-storage-policy
      # default storageclass for control plane and worker node pools
      - name: defaultStorageClass
        value: tkg-storage-policy