在 Google Distributed Cloud 中,使用者叢集會執行工作負載,而在多叢集架構中,使用者叢集是由管理員叢集建立及管理。
建立管理員叢集後,呼叫 bmctl create config
指令會建立 YAML 檔案,您可以編輯該檔案來定義使用者叢集。如要套用設定並建立使用者叢集,請使用 bmctl create cluster
指令。前置檢查適用於使用 bmctl create cluster
指令建立的使用者叢集。
將工作負載移出管理員叢集,可避免不需存取該資訊的使用者,取得管理員叢集儲存的 SSH 金鑰等機密管理資料。此外,將使用者叢集彼此分開,可為工作負載提供良好的整體安全性。
必要條件
- 系統會從 Cloud Storage 下載最新
bmctl
(gs://anthos-baremetal-release/bmctl/1.32.100-gke.106/linux-amd64/bmctl
)。 - 可存取叢集 API 伺服器 (
controlPlaneVIP
) 的工作管理員叢集。 - 管理員叢集節點與目標使用者叢集上的所有節點都有網路連線。
- 工作站執行
bmctl
,且與目標使用者叢集中的所有節點都有網路連線。 - 管理員工作站可以與每個使用者叢集節點建立 SSH 連線。
- 在管理員叢集上設定 Connect 註冊服務帳戶,以便搭配 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
區段下方的檔案頂端。如需使用者叢集設定範例,請參閱「叢集設定範例」中的「使用者叢集」。
根據預設,使用者叢集會沿用管理叢集的憑證。您可以選擇覆寫部分或所有憑證。
使用
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
。編輯設定檔,進行下列變更:
從設定中移除本機憑證檔案路徑:
...
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
,指定機群和 Connect 服務執行的 Google Cloud 區域。這項區域成員資格會將車隊服務流量限制在您的區域。如果在叢集規格中加入gkeConnect.location
,指定的區域必須與clusterOperations.location
中設定的區域相同。如果區域不同,叢集建立作業就會失敗。
- 如有需要,您也可以在叢集規格中新增
如果專案已啟用 GKE On-Prem API,專案中的所有叢集都會自動註冊 GKE On-Prem API,並使用
clusterOperations.location
中設定的區域。Google Cloud指定控制層節點的 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 網路」。
建立使用者叢集
發出 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
使用者叢集設定範例
如需使用者叢集設定範例,請參閱「叢集設定範例」中的「使用者叢集」。