建立使用者叢集

在 Google Distributed Cloud 中,使用者叢集可讓您在由管理員叢集控管的多叢集架構中,執行及隔離工作負載。將工作負載與管理員叢集區隔,可保護機密的管理資料 (例如儲存的安全殼層金鑰),而將使用者叢集彼此區隔,則可為應用程式提供多租戶安全性。

如要部署使用者叢集,請自訂叢集設定檔,定義節點集區和叢集設定,然後使用 bmctl 指令建立叢集。

必要條件

  • 從 Cloud Storage 下載最新的 bmctl (gs://anthos-baremetal-release/bmctl/1.36.200-gke.118/linux-amd64/bmctl)。
  • 可存取叢集 API 伺服器 (controlPlaneVIP) 的運作中管理員叢集。
  • 管理員叢集節點與目標使用者叢集上的所有節點之間,具有網路連線。
  • 執行 bmctl 的工作站可透過網路連線至目標使用者叢集中的所有節點。
  • 管理員工作站可與每個使用者叢集節點建立 SSH 連線。
  • 管理員叢集已設定 Connect-register 服務帳戶,可與 Connect 搭配使用。

啟用 SELinux

如要啟用 SELinux 來保護容器,請務必在所有主機上以 Enforced 模式啟用 SELinux。自 Google Distributed Cloud 1.9.0 版起,您可以在建立或升級叢集前後,啟用或停用 SELinux。Red Hat Enterprise Linux (RHEL) 預設會啟用 SELinux。如果主機機器已停用 SELinux,或您不確定是否已停用,請參閱「使用 SELinux 保護容器」一文,瞭解如何啟用。

Google Distributed Cloud 僅支援 RHEL 系統中的 SELinux。

建立使用者叢集設定檔

建立使用者叢集的設定檔,與建立管理員叢集的設定檔幾乎完全相同。唯一的差別在於,您需要移除本機憑證設定部分,讓設定成為有效的 Kubernetes 資源集合。設定部分位於檔案頂端的 bmctl configuration variables 部分下方。如需使用者叢集設定範例,請參閱叢集設定範例中的「使用者叢集」。

根據預設,使用者叢集會沿用管理叢集的管理員叢集憑證。您可以選擇覆寫部分或所有憑證。

  1. 使用 bmctl create config 指令建立使用者叢集設定檔:

    bmctl create config -c USER_CLUSTER_NAME
    

    例如,執行下列指令,為名為 user1 的使用者叢集建立設定檔:

    bmctl create config -c user1
    

    檔案會寫入 bmctl-workspace/user1/user1.yaml。檔案的一般路徑為 bmctl-workspace/CLUSTER NAME/CLUSTER_NAME.yaml。

  2. 編輯設定檔,並進行下列變更:

    • 從設定中移除本機憑證檔案路徑:

      ...
        gcrKeyPath: (path to Artifact Registry service account key)
        sshPrivateKeyPath: (path to SSH private key, used for node access)
        gkeConnectAgentServiceAccountKeyPath: (path to Connect agent service account key)
        gkeConnectRegisterServiceAccountKeyPath: (path to Hub registration service account key)
        cloudOperationsServiceAccountKeyPath: (path to Cloud Operations service account key)
      ...
      
    • 變更設定,將叢集類型指定為 user,而非 admin:

      ...
      spec:
        # Cluster type. This can be:
        #   1) admin:  to create an admin cluster. This can later be used to create
        #   user clusters.
        #   2) user:   to create a user cluster. Requires an existing admin cluster.
        #   3) hybrid: to create a hybrid cluster that runs admin cluster
        #   components and user workloads.
        #   4) standalone: to create a cluster that manages itself, runs user
        #   workloads, but does not manage other clusters.
        type: user
      ...
      
    • 在 gkeConnect.projectID 欄位中指定專案 ID,將叢集註冊至機群。這個專案稱為「機群主專案」。

      ...
      gkeConnect:
         projectID: my-project-123
      ...
      
      • 您也可以在叢集規格中加入 gkeConnect.location,指定 Fleet 和 Connect 服務執行的 Google Cloud 區域。這項區域性成員資格會將機群服務流量限制在您的區域。如果您在叢集規格中加入 gkeConnect.location,則指定的區域必須與 clusterOperations.location 中設定的區域相同。如果區域不同,叢集建立作業就會失敗。
    • 如果Google Cloud 專案已啟用 GKE On-Prem API,專案中的所有叢集都會在clusterOperations.location設定的區域中,自動註冊 GKE On-Prem API。

      • 如要將專案中的所有叢集註冊至 GKE On-Prem API,請務必按照「事前準備」中的步驟操作,在專案中啟用及使用 GKE On-Prem API。

      • 如果不想在 GKE On-Prem API 中註冊叢集,請加入這個區段,並將 gkeOnPremAPI.enabled 設為 false。如果不想在專案中註冊任何叢集,請在專案中停用 gkeonprem.googleapis.com (GKE On-Prem API 的服務名稱)。如需操作說明,請參閱「停用服務」。

    • 指定控制層節點的 IP 位址。

      ...
      # Sample control plane config
      controlPlane:
       nodePoolSpec:
         nodes:
         - address: 10.200.0.20
      ...
      
    • 請確認負載平衡器 VIP 和位址集區的管理員和使用者叢集規格互補,且不與現有叢集重疊。以下範例顯示一組管理員和使用者叢集設定,其中指定了負載平衡和位址集區:

      ...
      # Sample admin cluster config for load balancer and address pools
        loadBalancer:
          vips:
            controlPlaneVIP: 10.200.0.49
            ingressVIP: 10.200.0.50
          addressPools:
          - name: pool1
            addresses:
            - 10.200.0.50-10.200.0.70
      ...
      ...
      # Sample user cluster config for load balancer and address pools
      loadBalancer:
          vips:
            controlPlaneVIP: 10.200.0.71
            ingressVIP: 10.200.0.72
          addressPools:
          - name: pool1
            addresses:
            - 10.200.0.72-10.200.0.90
      ...
      

      其餘使用者叢集設定檔與管理員叢集設定相同。

    • 指定叢集節點的 Pod 密度:

      ...
      # NodeConfig specifies the configuration that applies to all nodes in the cluster.
      nodeConfig:
        # podDensity specifies the pod density configuration.
        podDensity:
          # maxPodsPerNode specifies at most how many pods can be run on a single node.
          maxPodsPerNode: 110
      ...
      

      如果是使用者叢集,maxPodsPerNode 的允許值為 32-250。如未指定,預設值為 110。叢集建立後,即無法更新這個值。

      Pod 密度也受限於叢集的可用 IP 資源。詳情請參閱「Pod 和 Service 網路」。

建立使用者叢集

執行 bmctl 指令,套用使用者叢集設定並建立叢集:

bmctl create cluster -c USER_CLUSTER_NAME --kubeconfig ADMIN_KUBECONFIG

更改下列內容:

  • USER_CLUSTER_NAME:上一節建立的叢集名稱。
  • ADMIN_KUBECONFIG:管理員叢集 kubeconfig 檔案的路徑。

舉例來說,如果使用者叢集名稱為 user1,管理員叢集 kubeconfig 檔案的路徑為 kubeconfig bmctl-workspace/admin/admin-kubeconfig,則指令如下:

bmctl create cluster -c user1 --kubeconfig bmctl-workspace/admin/admin-kubeconfig

預檢適用於使用 bmctl create cluster 指令建立的使用者叢集。

使用者叢集設定範例

如需使用者叢集設定範例,請參閱叢集設定範例中的「使用者叢集」。