建立獨立叢集

獨立叢集可讓您在自我管理的叢集上執行工作負載,不必在資源受限的環境中部署獨立的管理員叢集。您可以選擇兩種安裝設定檔:預設設定檔 (具有標準資源需求) 和邊緣設定檔 (可大幅降低邊緣裝置的系統資源需求)。

建立獨立叢集前,請先考量減少資源負擔和整體安全性之間的取捨。由於獨立叢集會自行管理,因此在同一個叢集上執行使用者工作負載,會增加安全殼層金鑰等機密管理資料外洩的風險。

必要條件

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

  • 從 Cloud Storage 下載最新的 bmctl (gs://anthos-baremetal-release/bmctl/1.36.200-gke.118/linux-amd64/bmctl)。
  • 執行 bmctl 的工作站與目標獨立叢集中的所有節點之間,具有網路連線。
  • 執行 bmctl 的工作站可透過網路連至目標獨立叢集的控制層 VIP。
  • 用於建立獨立叢集的安全殼層金鑰可供 root 使用,或目標獨立叢集中的所有節點都有 SUDO 使用者存取權。
  • Connect-register 服務帳戶已設定為與 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 指令通常可以在獨立工作站或其中一個獨立叢集節點上執行。不過,如果您要建立已啟用邊緣設定檔的獨立叢集,並已設定最低必要資源,建議您在獨立工作站上執行 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 和建立服務帳戶外,如果您具備適當的身分與存取權管理權限,也可以提供現有服務帳戶。這樣一來,您就可以在 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:Pod 使用的 IP 位址範圍,採用 CIDR 區塊標記法。建議的起始值為 192.168.0.0/16,系統會預填在產生的叢集設定檔中。

    • clusterNetwork.services.cidrBlocks:Service 使用的 IP 位址範圍,以 CIDR 區塊標記法表示。建議的起始值為 10.96.0.0/20,系統會預先填入產生的叢集設定檔。

    • loadBalancer.vips.controlPlaneVIP:叢集 Kubernetes API 伺服器的虛擬 IP (VIP) 位址。

    • loadBalancer.vips.ingressVIP:要用作輸入 Proxy 外部位址的 VIP 位址。

    • loadBalancer.addressPools.addresses::十個 IP 位址的範圍,可做為 LoadBalancer 類型 Service 的外部 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 和 Service 網路」。

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

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

bmctl create cluster -c CLUSTER_NAME

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

以下範例指令可建立名為 standalone1 的叢集:

bmctl create cluster -c standalone1

獨立叢集設定範例

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