Google Distributed Cloud 混合式叢集可讓您執行使用者工作負載,同時管理其他叢集和混合式叢集本身。在資源有限的環境中,結合管理員和使用者角色,可省去專用管理員叢集的負擔。獨立叢集只能管理自身,混合叢集則可建立及管理其他叢集。
將工作負載與控制元件託管在一起,雖然能提高彈性,但會犧牲安全性隔離,增加安全殼層金鑰等機密資產的暴露風險。您可以使用 bmctl 工具,從獨立工作站或直接在目標節點上,部署具有高可用性 (HA) 控制層的混合叢集。
必要條件
- 從 Cloud Storage 下載最新的
bmctl(gs://anthos-baremetal-release/bmctl/1.36.200-gke.118/linux-amd64/bmctl)。 - 執行
bmctl的工作站與目標混合式叢集中的所有節點之間,具有網路連線。 - 執行
bmctl的工作站與目標混合式叢集的控制層 VIP 之間有網路連線。 - 用於建立混合式叢集的安全殼層金鑰可供根目錄使用,或目標混合式叢集中的所有節點都有 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 並建立叢集設定檔
使用
gcloud auth application-default login以使用者身分登入 gcloud CLI:gcloud auth application-default login您必須具備專案擁有者或編輯者角色,才能使用自動啟用 API 和建立服務帳戶功能,詳情請參閱下列各節。
您也可以為使用者新增下列 IAM 角色:
- 服務帳戶管理員
- 服務帳戶金鑰管理員
- 專案 IAM 管理員
- Compute 檢視者
- 服務使用情形管理員
或者,如果您已有具備這些角色的服務帳戶,請執行:
export GOOGLE_APPLICATION_CREDENTIALS=JSON_KEY_FILE將
JSON_KEY_FILE替換為服務帳戶 JSON 金鑰檔案的路徑。取得 Google Cloud 專案 ID,以便建立叢集:
export CLOUD_PROJECT_ID=$(gcloud config get-value project)
使用 bmctl 建立叢集設定檔
登入 gcloud CLI 並設定專案後,您可以使用 bmctl 指令建立叢集設定檔。
如要建立叢集設定檔,請按照下列步驟操作:
執行下列指令,建立叢集設定檔、所有必要的服務帳戶,並啟用所有必要的 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旗標。不過,您必須在設定檔中手動指定憑證。如要進一步瞭解指令選項,請參閱「create config」。
編輯叢集設定檔
現在您已有叢集設定檔,請編輯該檔案,進行下列變更:
提供 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將叢集註冊至機群。您在
bmctl create config指令中指定的專案 ID 會自動新增至叢集設定檔中的gkeConnect.projectID欄位。這項專案稱為機群主專案。- 如果您使用自動啟用 API 和建立服務帳戶功能建立設定檔,可以略過這個步驟。
- 如果您在建立設定檔時,未使用自動啟用 API 和建立服務帳戶功能,請在叢集設定檔的對應
gkeConnectAgentServiceAccountKeyPath和gkeConnectRegisterServiceAccountKeyPath欄位中,參照下載的服務帳戶 JSON 金鑰。
變更設定,將叢集類型指定為
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變更設定,指定多節點的高可用性控制層。請指定奇數節點,以達到高可用性所需的多數仲裁:
# 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指定叢集節點的 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(非高可用性叢集)。如未指定,maxPodsPerNode的預設值為110。叢集建立後,即無法更新這個值。Pod 密度也受限於叢集的可用 IP 資源。詳情請參閱「Pod 和 Service 網路」。
使用叢集設定建立混合式叢集
使用 bmctl 指令建立叢集:
bmctl create cluster -c CLUSTER_NAME
將 CLUSTER_NAME 替換為您在上一節建立叢集設定檔時使用的名稱。
以下範例說明如何使用指令建立名為 hybrid1 的叢集:
bmctl create cluster -c hybrid1
混合式叢集設定範例
如需混合叢集設定範例,請參閱叢集設定範例中的「混合叢集」。