在 Bare Metal 上创建 global 集群

在 Bare Metal 上,需要运行两次 create。第一次运行会构建安装 ISO,然后停止。接着,使用该 ISO 注册主机并将其分配到池。第二次运行会安装集群。

前提条件

操作步骤

1. 写入 install-config.yaml

在 bootstrap 节点上创建安装目录,例如 /root/global-install,并在其中写入 install-config.yaml。本页中的命令将此目录称为 <install-dir>;请参阅安装目录。确保文件为私有文件(chmod 600 install-config.yaml)。

复制以下模板并填写占位符。编号行特定于 Bare Metal,相关说明见模板下方的表格。关于其他字段,请参阅通用 install-config.yaml 字段。关于 ac 根据此文件渲染的对象,请参阅渲染的清单。

install-config.yaml
global:
  bootstrapIP: <bootstrap-node-ip>
  registry:
    address: <host>:<port>
    username: <user>
    password: <password>
  platform:
    address: <platform-domain-or-ip>
    username: admin@cpaas.io
    password: <password>
    extraAddresses: []
    cert:
      certificateFile: <console-cert-file>
      privateKeyFile: <console-key-file>
      # pkcs12CertificateFile: <console-pkcs12-file>
      # pkcs12Password: <password>

cluster:
  sshKeys:
    - <ssh-public-key>
  ntpServers: []
  network:
    podCIDR: 10.199.0.0/16
    serviceCIDR: 10.96.0.0/12
    kubeOVN:
      joinCIDR: 100.64.0.0/16
    loadBalancer:
      type: internal
      address: <control-plane-endpoint>
      port: 6443
      vrid: <vrid>

provider:
  baremetal:
    # osType: alaudaos-k
    # architecture: arm64
    isoImageTag: <iso-image-tag>
    rootImageTag: <root-image-tag>
    serviceAccountSigningKey: <base64-pem-key>

controlPlane:
  replicas: 3
  deployMode: normal
  baremetal:
    machineInventoryPool: global-control-plane-pool

computes:
  - name: worker
    replicas: 3
    deployMode: normal
    baremetal:
      machineInventoryPool: global-worker-pool
#字段说明
global必需 · object用于安装 global 集群的设置。
1global.bootstrapIP必需 · stringbootstrap 节点地址:主机用来进行路由的 bootstrap 节点 IPv4 地址。请参阅网络。主机通过 https://<bootstrapIP>:12443 注册。
cluster.network必需 · object集群网络。
2cluster.network.loadBalancer必需 · objecttype:默认值为 internal,使用 provider 在控制平面节点上、持有节点地址的 NIC 上运行的自建 VIP。external 使用自有负载均衡器。在安装集群中添加其后端。address:VIP 或负载均衡器地址。必须是一个 IPv4 地址,不能是节点地址,并且必须位于 Pod、Service 和 join CIDR 之外。port:默认为 6443。vrid:与 internal 一起使用时必需。设置一个 1 到 255 之间的 VRRP 路由器 ID,并确保其在控制平面 Layer 2 域中唯一。使用 external 时,删除此字段。不支持 interface 和 vipMode。
provider.baremetal必需 · objectBare Metal 设置:主机 OS、OS 镜像和 ServiceAccount 签名密钥。
3provider.baremetal.osType可选 · string · 默认值:Alauda OS M55在主机 OS 和架构中选择的主机 OS。对于 Alauda OS KU,取消该行的注释,该行会设置 alaudaos-k。一个 global 集群只有一个 OS。此 OS 决定两个 OS 镜像、主机的 OS 标签以及镜像目录键。Registry 中的 OS 镜像中的生成器会打印此值。
4provider.baremetal.architecture可选 · string · 默认值:amd64在主机 OS 和架构中选择的主机架构:amd64 或 arm64。对于 arm64,取消该行的注释。arm64 需要 osType: alaudaos-k,因为 Alauda OS M55 仅针对 amd64 构建。如果主机架构与 bootstrap 节点的架构不同,请使用混合 Core Package。Registry 中的 OS 镜像中的生成器会为 arm64 打印此值。
5provider.baremetal.isoImageTag必需 · stringISO 镜像标签,不包含 registry 或 repository。它是 tkestack/baremetal-base-image-iso 的标签,或带有 osType: alaudaos-k 的 tkestack/kubeos-iso 的标签。安装 ISO 从此镜像构建。两个镜像标签都来自 Alauda OS 版本与平台版本匹配的 OS archive。请参阅版本映射。Registry 中的 OS 镜像中的生成器会打印此值。稍后查找该值时,请参阅查找镜像标签。
6provider.baremetal.rootImageTag必需 · string根文件系统镜像标签,不包含 registry 或 repository。它是 tkestack/baremetal-base-image 的标签,或带有 osType: alaudaos-k 的 tkestack/kubeos-rootfs 的标签。主机从此镜像安装。Registry 中的 OS 镜像中的生成器会打印此值,该值与 isoImageTag 的标签相同。稍后查找该值时,请参阅查找镜像标签。
7provider.baremetal.serviceAccountSigningKey可选 · string · 默认值:生成用于签名 ServiceAccount token 的 base64 编码 PEM 密钥。删除该行即可生成密钥。仅在灾难恢复对中设置此项,并确保两侧使用相同的值。请参阅生成共享密钥。
controlPlane必需 · object控制平面节点组。
8controlPlane.baremetal.machineInventoryPool必需 · string此节点组从中获取主机的 MachineInventoryPool。请在创建池中创建它。两个节点组不能共享一个池。
computes[]可选 · []object · 默认值:[]工作节点组,每个组对应一个条目。
9computes[].baremetal.machineInventoryPool必需 · string此工作组的 MachineInventoryPool。每个节点组都有自己的池。

在 Bare Metal 上,节点组只接受 replicas、deployMode 和 baremetal.machineInventoryPool,因为主机提供每个节点的大小、网络和磁盘。请勿设置 cpuCore、memoryGiB、network、disks、hosts 或 credentialRef。设置其中任何一项都会导致错误。

关于灾难恢复对两侧各自的值,请参阅创建 Global 集群灾难恢复对。

2. 构建安装 ISO

在 bootstrap 节点上:

<extract-dir>/res/<arch>/ac adm alpha global create --dir <install-dir> --provider baremetal

第一次运行会准备 bootstrap 集群、构建安装 ISO、打印其下载 URL 和校验和 URL,然后停止并显示错误:

The installation ISO is built. Boot every host of the global cluster from it:
  download: https://<bootstrapIP>:12443/...
  checksum: https://<bootstrapIP>:12443/...
...
error: the registration check did not pass, so nothing of the global cluster was applied:
  - pool missing: MachineInventoryPool cpaas-system/global-control-plane-pool, which controlPlane draws from, does not exist
  - pool missing: MachineInventoryPool cpaas-system/global-worker-pool, which computes[worker] draws from, does not exist

Register the hosts with the ISO and collect them into the pools, then run again:
  ac adm alpha global create --dir <install-dir> --provider baremetal --reuse-manifests
Everything done so far is kept and skipped

第一次运行出现此错误是预期行为。池尚不存在,因为还没有主机注册。global 集群尚未应用任何部分。请继续执行以下步骤。在安装集群中运行所打印的命令。

下载 ISO。通过校验和 URL 对其进行验证,可以在 bootstrap 节点上验证,也可以在下载 ISO 的机器上验证。校验和文件包含 ISO 的 SHA-256 哈希值和原始文件名。原始名称包含冒号,而 Windows 不允许文件名中包含冒号。因此,保存的文件通常具有不同的名称,sha256sum -c 无法找到该文件。请改为比较哈希值:

curl -sSk <checksum-url> | awk '{print $1}'    # expected hash
sha256sum <saved-iso-file> | awk '{print $1}'  # actual hash

两个哈希值相同后继续。否则,重新下载 ISO。在 Windows 上,certutil -hashfile <saved-iso-file> SHA256 会打印实际哈希值。

3. 注册主机

  1. 从 ISO 启动每台主机。每台主机会注册为名为 global-<system-uuid> 的 MachineInventory,并报告其磁盘。随后主机会停留在 live 环境中,直到你选择其系统磁盘。你可以同时启动所有主机。如果主机在 live 环境中未获取 DHCP 地址,请按照前提条件中的准备方式配置其网络。下载 URL 会在 ISO 构建 120 分钟后过期。如果已过期,请参阅ISO 下载 URL 已过期。此 ISO 仅用于本次安装。交接后请勿重复使用。

  2. 在 bootstrap 节点上,列出已注册的主机以及每台等待中的主机报告的磁盘。每台主机都会等待你选择磁盘,即使主机只有一个磁盘:

    <extract-dir>/res/<arch>/ac --kubeconfig /var/cpaas/data/alauda.kubeconfig \
      -n cpaas-system get machineinventories.elemental.cattle.io \
      -o custom-columns='NAME:.metadata.name,PHASE:.status.install.phase,IP:.metadata.labels.elemental\.cattle\.io/registration-ip'
    <extract-dir>/res/<arch>/ac --kubeconfig /var/cpaas/data/alauda.kubeconfig \
      -n cpaas-system get machineinventories.elemental.cattle.io <inventory-name> \
      -o jsonpath='{range .status.install.candidates[*]}{.id}{"\t"}{.eligible}{"\t"}{.path}{"\t"}{.sizeBytes}{"\t"}{.reasons}{"\n"}{end}'

    等待中的主机会显示 AwaitingTarget。IP 是主机用来访问 bootstrap 节点的地址,因此你可以将 inventory 与主机对应起来。每个候选行都会打印磁盘 ID、磁盘是否可选、其在 live 环境中的设备路径、以字节为单位的大小,以及无法选择该磁盘的原因(如有)。根据大小和路径识别系统磁盘。

  3. 在每台主机仍处于 live 环境期间,使用磁盘 ID 选择其系统磁盘:

    <extract-dir>/res/<arch>/ac --kubeconfig /var/cpaas/data/alauda.kubeconfig \
      -n cpaas-system annotate machineinventories.elemental.cattle.io <inventory-name> \
      baremetal.alauda.io/install-target-device=<disk-id>
    • 选择显示 true 的磁盘,并完全按照打印的内容使用其 ID。
    • 阶段变为 Installing,主机会将 Alauda OS 安装到该磁盘并重新启动。之后无法更改该选择。
    • 如果由于主机最近未被发现而导致 annotation 被拒绝,请确保主机仍在运行 ISO,然后再次运行该命令。
  4. 在 bootstrap 节点上再次列出已注册的主机:

    <extract-dir>/res/<arch>/ac --kubeconfig /var/cpaas/data/alauda.kubeconfig \
      -n cpaas-system get machineinventories.elemental.cattle.io \
      -o custom-columns='NAME:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status,PHASE:.status.install.phase,PLAN:.status.plan.secretRef.name'

    当 READY 为 True、PHASE 为 Installed,且 PLAN 不为 <none> 时,可以使用该主机。否则,请参阅Bare Metal 上的故障排除。

4. 创建池

为每个节点组创建一个 MachineInventoryPool。每个池必须:

  • 使用 install-config.yaml 提供的名称。
  • 设置 spec.clusterName: global。
  • 列出至少与从该池获取主机的节点组副本数相同数量的主机。

一台主机只能属于一个池。

pools.yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: MachineInventoryPool
metadata:
  name: global-control-plane-pool
  namespace: cpaas-system
spec:
  clusterName: global
  machineInventories:
    - name: <inventory-1>
      hostname: <hostname-1>
    - name: <inventory-2>
    - name: <inventory-3>
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: MachineInventoryPool
metadata:
  name: global-worker-pool
  namespace: cpaas-system
spec:
  clusterName: global
  machineInventories:
    - name: <inventory-4>
    - name: <inventory-5>
    - name: <inventory-6>
  1. hostname:可选。默认为 inventory 名称。

在 bootstrap 节点上:

<extract-dir>/res/<arch>/ac --kubeconfig /var/cpaas/data/alauda.kubeconfig apply -f pools.yaml

5. 安装集群

如果使用 external 负载均衡器,请在再次运行 create 前配置其转发规则。create 不会检查负载均衡器,控制平面会通过它初始化。将平台访问地址和 global VIP中在负载均衡器上转发列为是的每个端口,转发到 controlPlane.baremetal.machineInventoryPool 池中的每台主机。使用每台主机在 live 环境中获得的地址。安装完成后主机会保留该地址,即使该地址来自 DHCP。

在 bootstrap 节点上,再次运行 create,并重新使用第一次运行所渲染的清单:

<extract-dir>/res/<arch>/ac adm alpha global create --dir <install-dir> --provider baremetal --reuse-manifests

ac 首先检查 install-config.yaml 中命名的池(其成员和大小)以及 ISO URL。如果检查失败,则不会应用 global 集群的任何部分,并且错误会指出失败的项目。

安装完成后,create 返回。如果 create 停止,请再次运行相同的命令。它会跳过已经完成的工作。请参阅 create 命令。

6. 监控安装

在 bootstrap 节点上的另一个终端中:

<extract-dir>/res/<arch>/ac adm alpha global status

关于阶段和常见故障,请参阅故障排除。关于 Bare Metal 故障,请参阅Bare Metal 上的故障排除。

验证

当 create 返回时,安装即完成,但某些平台组件可能还需要几分钟才能就绪。在判断结果之前,请按照适用于 Alauda OS 的其他检查中的说明等待这些组件就绪。然后按照验证中的说明验证平台,包括其中的Alauda OS 检查。

适用于:自建 VIP(cluster.network.loadBalancer.type: internal)。使用 external 负载均衡器时跳过此检查。

以 boot 用户(ssh boot@<control-plane-node-ip>)身份登录 global 集群的控制平面节点。使用与 cluster.sshKeys 中的 SSH 公钥匹配的私钥。使用 sudo 运行 curl,因为只有 root 可以读取集群 CA 文件:

sudo curl --cacert /etc/kubernetes/pki/ca.crt https://<control-plane-vip>:6443/healthz

当其输出 ok 时继续操作。否则,请参阅Bare Metal 上的故障排除。

后续步骤

  • 灾难恢复对:继续执行安装主集群和备用集群。
  • 要在 Bare Metal 上创建工作负载集群,请按照为主机准备 Alauda OS和注册主机中的说明准备 OS 并注册主机,然后按照在 Bare Metal 上创建集群进行操作。global 集群已运行 Bare Metal provider。它还已为 install-config.yaml 中的 osType 和 architecture 准备好 OS 镜像和镜像目录密钥。对于使用该 OS 和架构的主机,只需创建注册信息及其 ISO。对于使用其他架构或 OS 的主机,还需要推送镜像并添加密钥。请参阅添加镜像目录密钥。
  • 要在其他基础设施上创建工作负载集群,请按照准备中的说明安装相应的 provider。