建立獨立叢集

本頁說明如何建立獨立叢集,也就是執行工作負載的自我管理叢集。獨立叢集不會管理其他叢集,因此在資源受限的情況下,不需要執行獨立的管理員叢集。此外,獨立叢集提供兩種安裝設定檔供您選擇:

  • 預設:預設設定檔的資源需求有限。
  • Edge:Edge 設定檔大幅降低了系統資源需求,建議用於資源限制較高的邊緣裝置。

建立獨立叢集前,請先考量減少資源與整體安全性之間的取捨。由於獨立叢集會自行管理,在同一叢集上執行工作負載會增加暴露敏感管理資料 (例如 SSH 金鑰) 的風險。

必要條件

建立獨立叢集前,請確認下列事項:

  • 從 Cloud Storage 下載最新 bmctl (gs://anthos-baremetal-release/bmctl/1.36.100-gke.144/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 保護容器安全」一文,瞭解如何啟用 SELinux。

Google Distributed Cloud 僅支援 RHEL 系統中的 SELinux。

建立獨立叢集

您可以使用 bmctl 指令,建立具有單一控制節點層的獨立叢集。這類設定可減少資源耗用量,但無法提供高可用性 (HA),且產生的叢集會有單一故障點。

您也可以建立高可用性獨立叢集。在高可用性模式下,如果節點故障,其他節點會取代該節點。如要建立高可用性獨立叢集,您必須為控制層指定至少三個節點。

bmctl 指令通常可在獨立工作站或其中一個獨立叢集節點上執行。不過,如果您要建立啟用邊緣設定檔的獨立叢集,並已設定最低必要資源,建議在獨立工作站上執行 bmctl。

登入「gcloud」

  1. 以使用者身分登入 gcloud:

    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)
    

建立獨立叢集設定檔

登入 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

編輯叢集設定檔

現在您已有叢集設定檔,請對其進行下列變更:

  1. 新增安全殼層私密金鑰,以存取獨立叢集節點:

    # 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 和建立服務帳戶功能,請在叢集設定檔的對應 gkeConnectAgentServiceAccountKeyPath 和 gkeConnectRegisterServiceAccountKeyPath 欄位中,參照下載的服務帳戶 JSON 金鑰。
  3. 將設定變更為指定 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
    
  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. 在叢集設定檔中,填寫或編輯叢集網路詳細資料:

    • 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 位址不得與這個範圍重疊。

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

使用叢集設定建立獨立叢集

使用 bmctl 指令部署獨立叢集:

bmctl create cluster -c CLUSTER_NAME

將 CLUSTER_NAME 替換為您在前一節建立的叢集名稱。

以下範例顯示如何建立名為 standalone1 的叢集:

bmctl create cluster -c standalone1

獨立叢集設定範例

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