建立管理員叢集

管理員叢集可讓您建立、更新、升級及刪除使用者叢集。將叢集管理與使用者工作負載分開,有助於保護安全殼層金鑰和服務帳戶憑證等機密資料,但缺點是需要專門的管理資源。

在高可用性 (HA) 設定中,管理員叢集會提供備援控制層節點,因此即使單一節點故障,管理作業仍可繼續進行。您可以使用 bmctl 指令建立管理員叢集。建立叢集後,您會部署使用者叢集來執行工作負載。

必要條件

  • 從 Cloud Storage 下載最新的 bmctl (gs://anthos-baremetal-release/bmctl/1.36.200-gke.118/linux-amd64/bmctl)。
  • 執行 bmctl 的工作站可透過網路連線至目標使用者叢集中的所有節點。
  • 執行 bmctl 的工作站與叢集 API 伺服器 (控制層 VIP) 之間有網路連線。
  • 用於建立管理員叢集的安全殼層金鑰,可供 root 或在目標管理員叢集所有節點上,具備無密碼 sudo 權限的非超級使用者使用。
  • Connect-register 服務帳戶已設定為與 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 環境變數。

以下範例說明如何為與專案 ID my-gcp-project 相關聯的管理員叢集 admin1 建立設定檔:

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 和建立服務帳戶功能,請在叢集設定檔的對應 gkeConnectAgentServiceAccountKeyPath 和 gkeConnectRegisterServiceAccountKeyPath 欄位中,參照下載的服務帳戶 JSON 金鑰。

    • 您也可以在叢集規格中加入 gkeConnect.location,指定 Fleet 和 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. 如果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 的服務名稱)。如需操作說明,請參閱「停用服務」。

  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 和 Service 網路」。

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

使用 bmctl 指令部署叢集:

bmctl create cluster -c ADMIN_CLUSTER_NAME

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

以下範例指令可建立名為 admin1 的叢集:

bmctl create cluster -c admin1

管理員叢集設定範例

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