本頁面說明如何建立獨立叢集,也就是執行工作負載的自我管理叢集。獨立叢集不會管理其他叢集,因此在資源受限的情況下,不需要執行個別的管理員叢集。此外,獨立叢集提供兩種安裝設定檔供您選擇:
- 預設:預設設定檔的資源需求設有限制。
- Edge:Edge 設定檔大幅減少了系統資源需求,建議資源高度受限的邊緣裝置使用。
建立獨立叢集前,請先考量減少資源與整體安全性之間的取捨。由於獨立叢集會自行管理,在同一叢集上執行工作負載會增加暴露敏感管理資料 (例如 SSH 金鑰) 的風險。
必要條件
建立獨立叢集前,請確認下列事項:
- 系統會從 Cloud Storage 下載最新
bmctl
(gs://anthos-baremetal-release/bmctl/1.32.100-gke.106/linux-amd64/bmctl
)。 - 工作站
bmctl
與目標獨立叢集中的所有節點都有網路連線。 - 執行
bmctl
的工作站與目標獨立叢集的控制層 VIP 之間有網路連線。 - 用於建立獨立叢集的 SSH 金鑰可供超級使用者使用,或目標獨立叢集的所有節點都有 SUDO 使用者存取權。
- 設定 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。
建立獨立叢集
您可以使用 bmctl
指令建立具有單一控制節點層的獨立叢集。這類設定會減少資源耗用量,但不會提供高可用性 (HA),且產生的叢集會有單一故障點。
您也可以建立高可用性獨立叢集。在高可用性模式下,如果某個節點發生故障,其他節點會取而代之。如要建立高可用性獨立叢集,您必須為控制層指定至少三個節點。
bmctl
指令通常可在獨立工作站或獨立叢集節點上執行。不過,如果您要建立啟用 Edge 設定檔的獨立叢集,並已設定最低必要資源,建議在獨立工作站上執行 bmctl
。
登入「gcloud
」
以使用者身分登入
gcloud
: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)
建立獨立叢集設定檔
登入 gcloud CLI 並設定專案後,您可以使用 bmctl
指令建立叢集設定檔。在本例中,所有服務帳戶都是由 bmctl create config
指令自動建立:
bmctl create config -c STANDALONE_CLUSTER_NAME --enable-apis \
--create-service-accounts --project-id=$CLOUD_PROJECT_ID
更改下列內容:
- STANDALONE_CLUSTER_NAME 改成您要建立的獨立叢集名稱。
範例
下列指令會建立名為 standalone1
的獨立叢集設定檔,並與專案 ID my-gcp-project
建立關聯:
bmctl create config -c standalone1 --create-service-accounts --project-id=my-gcp-project
檔案會寫入 bmctl-workspace/standalone1/standalone1.yaml
。
除了自動啟用 API 和建立服務帳戶,您也可以提供現有的服務帳戶 (如果您有適當的 IAM 權限)。這樣一來,您就可以略過 bmctl
指令中先前的自動服務帳戶建立步驟:
bmctl create config -c standalone1
編輯叢集設定檔
現在您已有叢集設定檔,請對其進行下列變更:
新增安全殼層私密金鑰,存取獨立叢集節點:
# 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 金鑰。
將設定變更為指定
standalone
叢集類型,而非admin
。如要啟用邊緣設定檔,盡量減少資源耗用量,請指定profile: edge
: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: standalone # Edge profile minimizes the resource consumption of Google Distributed Cloud. It is only available for standalone clusters. profile: edge
(選用) 變更設定,指定多節點、高可用性控制層。為確保高可用性,請指定奇數節點,以達到絕對多數:
# 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
如果新增或移除節點時,節點數量暫時為偶數,只要達到法定人數,部署作業就會維持高可用性。
在叢集設定檔中,填寫或編輯叢集網路詳細資料:
clusterNetwork.pods.cidrBlocks
:以 CIDR 區塊標記法表示的 IP 位址範圍,供 Pod 使用。建議的起始值為192.168.0.0/16
,這會預先填入產生的叢集設定檔。clusterNetwork.services.cidrBlocks
:以 CIDR 區塊標記法表示的 IP 位址範圍,供服務使用。建議的起始值為10.96.0.0/20
,這個值會預先填入產生的叢集設定檔。loadBalancer.vips.controlPlaneVIP
:叢集 Kubernetes API 伺服器的虛擬 IP (VIP) 位址。loadBalancer.vips.ingressVIP
:用來做為 Ingress 代理伺服器外部位址的 VIP 位址。loadBalancer.addressPools.addresses:
:十個 IP 位址的範圍,可用於 LoadBalancer 類型的服務做為外部 IP 位址。請注意,這個範圍包含 MetalLB 必要的 Ingress VIP。其他 IP 位址不得與這個範圍重疊。
指定叢集節點的 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
的允許值為 HA 叢集的32-250
,以及非 HA 叢集的64-250
。如果未指定,預設值為110
。叢集建立後,這個值就無法更新。Pod 密度也會受到叢集可用 IP 資源的限制。詳情請參閱「Pod 網路」。
使用叢集設定建立獨立叢集
使用 bmctl
指令部署獨立叢集:
bmctl create cluster -c CLUSTER_NAME
將 CLUSTER_NAME 改成您在前一節建立的叢集名稱。
以下範例顯示如何建立名為 standalone1
的叢集:
bmctl create cluster -c standalone1
獨立叢集設定範例
如需獨立叢集設定範例,請參閱「叢集設定範例」中的「獨立叢集」。