创建独立集群

本页面介绍如何创建独立集群,该集群是自行管理工作负载的自行管理集群。独立集群不管理其他集群,因此无需在资源受限的情况下运行单独的管理员集群。此外,独立集群还提供两个安装配置文件供您选择:

  • 默认:默认配置文件具有资源受限要求。
  • 边缘:边缘配置文件显著降低了系统资源要求,建议用于资源限制条件较高的边缘设备。

在创建独立集群之前,请考虑在减少资源和整体安全性之间进行权衡。由于独立集群管理自身,因此在同一集群上运行工作负载会增加泄露敏感的管理数据(如 SSH 密钥)的风险。

前提条件

在创建独立集群之前,请确保满足以下条件:

  • 从 Cloud Storage 下载了最新的 bmctl (gs://anthos-baremetal-release/bmctl/1.14.11/linux-amd64/bmctl)。
  • 运行 bmctl 的工作站与目标独立集群中的所有节点有网络连接。
  • 运行 bmctl 的工作站与目标独立集群的控制平面 VIP 有网络连接。
  • 用于创建独立集群的 SSH 密钥可供 root 用户使用,或者 SUDO 用户可以访问目标独立集群中的所有节点。
  • Connect-register 服务账号配置为与 Connect 一起使用。

启用 SELinux

如果要启用 SELinux 来保护容器,则必须确保在所有宿主机上以 Enforced 模式启用 SELinux。从 GKE on Bare Metal 1.9.0 版或更高版本开始,您可以在创建集群或升级集群之前或之后启用或停用 SELinux。Red Hat Enterprise Linux (RHEL) 和 CentOS 上默认启用 SELinux。如果宿主机上停用了 SELinux,或者不确定,请参阅使用 SELinux 保护容器,了解如何启用 SELinux。

GKE on Bare Metal 仅支持 RHEL 和 CentOS 系统中的 SELinux。

创建独立集群

您可以使用 bmctl 命令创建具有单个控制节点层面的独立集群。这种类型的配置可以减少资源消耗量,但无法提供高可用性 (HA),并且生成的集群具有单一故障点。

您还可以创建高可用性独立集群。在高可用性模式下,如果节点发生故障,其他节点将取代它。如需创建高可用性独立集群,您必须为控制平面指定至少三个节点。

bmctl 命令通常可以在单独的工作站或某一个独立集群节点上运行。但是,如果您要创建启用了边缘配置文件的独立集群,并配置了最低资源要求,我们建议在单独的工作站上运行 bmctl

登录 gcloud

  1. 以用户身份登录 gcloud

    gcloud auth application-default login
    

    您需要具有 Project Owner 或 Editor 角色才能使用如下所述的自动 API 启用和服务账号创建功能。

    您还可以向用户添加以下 IAM 角色:

    • Service Account Admin
    • Service Account Key Admin
    • Project IAM Admin
    • Compute Viewer
    • Service Usage Admin

    或者,如果您已有具备这些角色的服务账号,请运行以下命令:

    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 并设置项目后,您可以使用 bmctl 命令创建集群配置文件。在此示例中,所有服务账号都由 bmctl create config 命令自动创建:

bmctl create config -c STANDALONE_CLUSTER_NAME --enable-apis \
    --create-service-accounts --project-id=$CLOUD_PROJECT_ID

替换以下内容:

  • STANDALONE_CLUSTER_NAME 替换为您要创建的独立集群的名称。

示例

以下命令会为与项目 ID my-gcp-project 关联的名为 standalone1 的独立集群创建配置文件:

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. 添加 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
    
  2. 舰队注册集群。您在 bmctl create config 命令中指定的项目 ID 会自动添加到集群配置文件中的 gkeConnect.projectID 字段。此项目即为舰队宿主项目

    • 如果您使用自动 API 启用和服务账号创建功能创建配置文件,则可以跳过此步骤。
    • 如果您不使用自动 API 启用和服务账号创建功能创建配置文件,请在集群配置文件的相应 gkeConnectAgentServiceAccountKeyPathgkeConnectRegisterServiceAccountKeyPath 字段中引用下载的服务账号 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 GKE on Bare Metal. 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. 指定集群节点的 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(HA 集群)和 64-250(非 HA 集群)。如果未指定,则默认值为 110。集群创建后,此值无法更新。

    pod 密度也受集群的可用 IP 资源的限制。如需了解详情,请参阅 pod 网络

使用集群配置创建独立集群

使用 bmctl 命令部署独立集群:

bmctl create cluster -c CLUSTER_NAME

CLUSTER_NAME 替换为您在上一步中创建的集群的名称。

以下示例命令创建名为 standalone1 的集群:

bmctl create cluster -c standalone1

独立集群配置示例

如需查看独立集群配置示例,请参阅集群配置示例中的独立集群