建立管理員叢集

在 Google Distributed Cloud 中,您可以設定管理員叢集,安全地管理其他叢集。您可以透過管理員叢集建立、更新、升級或刪除使用者叢集。使用者叢集會與管理作業分開執行工作負載,因此可保護機密資訊。

管理多叢集工作負載的管理員叢集可提供高可用性 (HA) 可靠性。在高可用性叢集中,如果一個控制層節點故障,其他節點會繼續運作。

在多叢集環境中,管理員叢集可提供最佳的基本安全性。由於管理資料的存取權與工作負載分開,因此存取使用者工作負載的人員無法存取機密管理資料,例如 SSH 金鑰和服務帳戶資料。因此,安全性和所需資源之間會有所取捨,因為獨立的管理員叢集代表您需要專屬資源來管理和處理工作負載。

您可以使用 bmctl 指令建立管理員叢集。建立管理員叢集後,請建立使用者叢集來執行工作負載。

需求條件:

  • 系統會從 Cloud Storage 下載最新 bmctl (gs://anthos-baremetal-release/bmctl/1.32.100-gke.106/linux-amd64/bmctl)。
  • 工作站執行 bmctl,且與目標使用者叢集中的所有節點都有網路連線。
  • 執行 bmctl 的工作站與叢集 API 伺服器 (控制層 VIP) 之間有網路連線。
  • 用於建立管理員叢集的 SSH 金鑰,可供root在目標管理員叢集的所有節點上,具備免密碼 sudo 權限的非根使用者使用。
  • 設定 Connect 註冊服務帳戶,以便搭配 Connect 使用。

如需建立混合叢集的逐步操作說明,請參閱 Google Distributed Cloud 快速入門。建立管理員叢集與建立混合式叢集類似,但您不會在管理員叢集上執行工作負載。

啟用 SELinux

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

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

登入 gcloud CLI 並建立管理員叢集設定檔

  1. 使用下列指令設定 Google Distributed Cloud 可用來建立叢集的預設憑證:

    gcloud auth application-default login
    
  2. 如要在這個頁面中使用自動啟用 API 和建立服務帳戶的功能,請將專案擁有者角色授予該主體。如果主體無法擔任專案擁有者角色,請完成下一個步驟。

  3. 為確保叢集建立作業順利完成,而不需授予專案擁有者角色,請將下列 IAM 角色新增至主體:

    • 服務帳戶管理員
    • 服務帳戶金鑰管理員
    • 專案 IAM 管理員
    • Compute 檢視者
    • 服務使用情形管理員

    如果主體是具有這些角色的服務帳戶,您可以執行下列指令:

    export GOOGLE_APPLICATION_CREDENTIALS=JSON_KEY_FILE
    

    JSON_KEY_FILE 替換為服務帳戶的 JSON 金鑰檔案路徑。

  4. 取得 Google Cloud 專案的 ID,並儲存在環境變數中,以便用於建立叢集:

    export CLOUD_PROJECT_ID=$(gcloud config get-value project)
    

使用 bmctl 建立管理員叢集設定

登入 gcloud CLI 並設定專案後,即可使用 bmctl 指令建立叢集設定檔。

在下列範例中,所有服務帳戶都是由 bmctl create config 指令自動建立:

bmctl create config -c ADMIN_CLUSTER_NAME --enable-apis \
    --create-service-accounts --project-id=CLOUD_PROJECT_ID

更改下列內容:

  • ADMIN_CLUSTER_NAME:新叢集的名稱。
  • CLOUD_PROJECT_ID:您的 Google Cloud 專案 ID 或 $CLOUD_PROJECT_ID 環境變數。

以下範例會建立管理員叢集的設定檔,該叢集名為 admin1,且與專案 ID my-gcp-project 相關聯:

bmctl create config -c admin1 --create-service-accounts --enable-apis --project-id=my-gcp-project

檔案會寫入 bmctl-workspace/admin1/admin1.yaml

除了自動啟用 API 和建立服務帳戶,您也可以為現有服務帳戶提供適當的 IAM 權限。也就是說,您可以在 bmctl 指令中略過上一個範例的自動服務帳戶建立作業:

bmctl create config -c admin1 --project-id=my-gcp-project

編輯叢集設定檔

您現在有了叢集設定檔,請編輯該檔案,進行下列變更:

  1. 提供 SSH 私密金鑰,以存取管理員叢集節點:

    # bmctl configuration variables. Because this section is valid YAML but not a valid Kubernetes
    # resource, this section can only be included when using bmctl to
    # create the initial admin/admin cluster. Afterwards, when creating user clusters by directly
    # applying the cluster and node pool resources to the existing cluster, you must remove this
    # section.
    gcrKeyPath: bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-gcr.json
    sshPrivateKeyPath: /path/to/your/ssh_private_key
    gkeConnectAgentServiceAccountKeyPath: bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-connect.json
    gkeConnectRegisterServiceAccountKeyPath: bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-register.json
    cloudOperationsServiceAccountKeyPath: bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-cloud-ops.json
    
  2. 將叢集註冊至機群。您在 bmctl create config 指令中指定的專案 ID,會自動新增至叢集設定檔的 gkeConnect.projectID 欄位。這個專案稱為「機群主專案」

    • 如果您是使用自動啟用 API 和建立服務帳戶的功能建立設定檔,可以略過這個步驟。

    • 如果您建立設定檔時未使用自動啟用 API 和建立服務帳戶功能,請在叢集設定檔的對應 gkeConnectAgentServiceAccountKeyPathgkeConnectRegisterServiceAccountKeyPath 欄位中,參照下載的服務帳戶 JSON 金鑰。

    • 如有需要,您也可以在叢集規格中新增 gkeConnect.location,指定機群和 Connect 服務執行的 Google Cloud 區域。這項區域成員資格會將車隊服務流量限制在您的區域。如果在叢集規格中加入 gkeConnect.location,指定的區域必須與 clusterOperations.location 中設定的區域相同。如果區域不同,叢集建立作業就會失敗。

  3. 檢查設定,確認指定叢集類型為 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: admin
    
  4. 如果專案已啟用 GKE On-Prem API,專案中的所有叢集都會自動註冊 GKE On-Prem API,並使用 clusterOperations.location 中設定的區域。Google Cloud

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

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

  5. 變更設定檔,指定多節點高可用性控制層。 為確保高可用性,請指定奇數節點,以達到絕對多數:

      # Control plane configuration
      controlPlane:
        nodePoolSpec:
          nodes:
          # Control plane node pools. Typically, this is either a single machine
          # or 3 machines if using a high availability deployment.
          - address: 10.200.0.4
          - address: 10.200.0.5
          - address: 10.200.0.6
    
  6. 指定叢集節點的 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: 250
    ....
    

    如果是管理員叢集,maxPodsPerNode 的允許值為高可用性叢集的 32-250,以及非高可用性叢集的 64-250。如果未指定,預設值為 110。叢集建立後,這個值就無法更新。

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

使用叢集設定建立管理員叢集

使用 bmctl 指令部署叢集:

bmctl create cluster -c ADMIN_CLUSTER_NAME

ADMIN_CLUSTER_NAME 會指定上一節中建立的叢集名稱。

以下範例顯示如何建立名為 admin1 的叢集:

bmctl create cluster -c admin1

管理員叢集設定範例

如需管理員叢集設定範例,請參閱「叢集設定範例」中的「管理員叢集」。