建立混合式叢集

在 Google Distributed Cloud 中,混合式叢集同時扮演管理員叢集和使用者叢集的雙重角色。執行工作負載,同時管理其他叢集和自身。

在資源受限的情況下,混合式叢集可免除執行獨立管理員叢集的需求,並提供高可用性 (HA) 的可靠性。在高可用性混合式叢集中,如果某個節點故障,其他節點會取而代之。

混合叢集與獨立叢集不同,因為混合叢集還能管理其他叢集。獨立叢集無法建立或管理其他叢集。

不過,建立混合式叢集時,您必須在彈性和安全性之間做出取捨。由於混合式叢集會自行管理,在相同叢集上執行工作負載會增加機密管理資料 (例如 SSH 金鑰) 的安全風險。

您可以使用 bmctl 指令,建立具有高可用性 (HA) 控制層的混合式叢集。bmctl 指令可以在獨立的工作站或混合式叢集節點上執行。

必要條件

  • 系統會從 Cloud Storage 下載最新 bmctl (gs://anthos-baremetal-release/bmctl/1.32.100-gke.106/linux-amd64/bmctl)。
  • 工作站執行 bmctl,且與目標混合式叢集中的所有節點都有網路連線。
  • 執行 bmctl 的工作站與目標混合式叢集的控制層 VIP 之間有網路連線。
  • 用於建立混合式叢集的 SSH 金鑰可供根使用者使用,或目標混合式叢集中的所有節點都有 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 並建立叢集設定檔

  1. 以使用者的身分登入 gcloud CLI (使用 gcloud auth application-default login):

    gcloud auth application-default login
    

    您必須具備專案擁有者或編輯者角色,才能使用下列章節所述的自動啟用 API 和建立服務帳戶功能。

    您也可以為使用者新增下列 IAM 角色:

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

    或者,如果您已有具備這些角色的服務帳戶,請執行下列指令:

    export GOOGLE_APPLICATION_CREDENTIALS=JSON_KEY_FILE
    

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

  2. 取得 Google Cloud 專案 ID,用於建立叢集:

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

使用 bmctl 建立叢集設定檔

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

如要建立叢集設定檔,請按照下列步驟操作:

  1. 執行下列指令,建立叢集設定檔、建立所有必要的服務帳戶,並啟用所有必要 API:

    bmctl create config -c CLUSTER_NAME</var> --enable-apis \
        --create-service-accounts --project-id=CLOUD_PROJECT_ID
    

    更改下列內容:

    • CLUSTER_NAME:您要建立的叢集名稱。
    • CLOUD_PROJECT_ID:您的 Google Cloud 專案 ID。

    根據預設,設定檔會寫入 bmctl-workspace/CLUSTER_NAME/CLUSTER_NAME.yaml

    如果您已啟用 API 並建立服務帳戶,則可直接建立設定檔,不必再啟用 API 和建立服務帳戶。您也不必使用 --project-id 旗標。不過,您必須在設定檔中手動指定憑證。

    如要進一步瞭解指令選項,請參閱「建立設定」。

編輯叢集設定檔

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

  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/hybrid 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 金鑰。
  3. 變更設定,指定叢集類型為 hybrid,而非 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: hybrid
    
  4. 變更設定,指定多節點高可用性控制層。 您希望指定奇數節點,以確保高可用性:

      # 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
    
  5. 指定叢集節點的 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 (適用於 HA 叢集) 和 64-250 (適用於非 HA 叢集)。如未指定,maxPodsPerNode 的預設值為 110。叢集建立後,就無法更新這個值。

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

使用叢集設定建立混合式叢集

使用 bmctl 指令建立叢集:

bmctl create cluster -c CLUSTER_NAME

CLUSTER_NAME 替換為您在上一節建立叢集設定檔時使用的名稱。

以下範例顯示建立名為 hybrid1 的叢集時所用的指令:

bmctl create cluster -c hybrid1

混合式叢集設定範例

如需混合叢集設定範例,請參閱「叢集設定範例」中的「混合叢集」。