启用或停用 VM Runtime on GDC

本文档介绍如何通过更新 VMRuntime 自定义资源或运行 bmctl 命令来启用或停用 VM Runtime on Google Distributed Cloud。

准备工作

如需启用或停用 VM Runtime on GDC,您需要以下资源和工具的访问权限:

启用 VM Runtime on GDC

VM Runtime on GDC 自动安装在 Google Distributed Cloud 1.10 版或更高版本中,但默认情况下处于停用状态。您必须先启用 VM Runtime on GDC,然后才能在 Google Distributed Cloud 中运行虚拟机资源。

bmctl

  • 如需启用运行时,请使用 bmctl 工具:

    bmctl enable vmruntime --kubeconfig KUBECONFIG_PATH
    

    提供集群的 kubeconfig 文件的路径。当您创建集群时,Google Distributed Cloud 会在管理员工作站上生成 kubeconfig 文件。默认情况下,路径为 bmctl-workspace/CLUSTER_NAME/CLUSTER_NAME-kubeconfig

    如果 VM Runtime on GDC 已启用,则该命令会返回错误。

您可以通过修改 VMRuntime 自定义资源来配置其他设置(例如模拟或图片格式)。

自定义资源

如需启用运行时,请更新 VMRuntime 自定义资源。此自定义资源是默认安装的。

  1. 修改 VMRuntime 自定义资源:

    kubectl edit vmruntime
    
  2. 在规范中设置 enabled:true

    apiVersion: vm.cluster.gke.io/v1
    kind: VMRuntime
    metadata:
      name: vmruntime
    spec:
      enabled: true
      # useEmulation defaults to "false" if not set.
      useEmulation: true
      # vmImageFormat defaults to "qcow2" if not set.
      vmImageFormat: qcow2
    

    在前面的 spec 部分中,可以设置以下值:

    • enabled:设置为 true 以启用 VM Runtime on GDC
    • useEmulation:如果您的节点不支持硬件虚拟化,或您不确定,请将值设置为 true。如果适用,硬件虚拟化可提供比软件模拟更好的性能。如果未指定 useEmulation 字段,则默认为 false
    • vmImageFormat:支持两个磁盘映像格式值:rawqcow2。如果未设置 vmImageFormat,则 VM Runtime on GDC 使用 raw 磁盘映像格式来创建虚拟机。raw 格式可以提供比 qcow2(一种写入时复制格式)更高的性能,但可以使用更多磁盘。如需详细了解虚拟机的映像格式,请参阅 QEMU 文档中的磁盘映像文件格式
  3. 在编辑器中保存自定义资源。

  4. 验证 VMRuntime 自定义资源是否已启用:

    kubectl describe vmruntime vmruntime
    

    VMRuntime 自定义资源的详细信息包含 Status 部分。当 VMRuntime.Status.Ready 显示为 true 时,VM Runtime on GDC 已启用并正常运行。

停用 VM Runtime on GDC

如果您不再需要使用 VM Runtime on GDC,可以停用此功能。

bmctl

  • 如需停用运行时,请使用 bmctl 工具:

    bmctl disable vmruntime --kubeconfig KUBECONFIG_PATH \
      --force=true
    

    提供集群的 kubeconfig 文件的路径和以下配置选项的值:

    • --force:设置为 true 以确认您要删除现有虚拟机资源。默认值为 false

自定义资源

如需停用运行时,请更新 VMRuntime 自定义资源:

  1. 修改 VMRuntime 自定义资源:

    kubectl edit vmruntime
    
  2. 在规范中设置 enabled:false

    apiVersion: vm.cluster.gke.io/v1`
    kind: VMRuntime
    metadata:
      name: vmruntime
    spec:
      enabled: false
      useEmulation: true
      vmImageFormat: qcow2
    
  3. 在编辑器中保存更新后的自定义资源规范。

  4. 如需验证 VMRuntime 自定义资源已停用,请查看在 vm-system 命名空间中运行的 Pod:

    kubectl get pods --namespace vm-system
    

    如果只有属于 vmruntime-controller-manager 部署的 Pod 在命名空间中运行,则表明 VM Runtime on GDC 已停用。

了解运行虚拟机的行为

baremetal.cluster.gke.io/vmrumtime-force-disable 注解可用于 VM Runtime on GDC 资源,以定义在集群中运行虚拟机时运行时环境处于停用状态时的行为。

以下示例展示了此注释的值已默认设置为 false

// VM runtime yaml file
apiVersion: vm.cluster.gke.io/v1
kind: VMRuntime
metadata:
  annotations:
    baremetal.cluster.gke.io/vmrumtime-force-disable: "false"
  name: vmruntime
[...]

当此注解设置为 false 时,VM Runtime on GDC 会尝试保护正在运行的虚拟机。在停用 VM Runtime on GDC 之前删除所有正在运行的虚拟机,或使用 bmctl disable vmruntime 命令指定 --force=true 参数,如上一部分所示。

下表说明了当此注释设置为 truefalse 时正在运行的虚拟机会发生什么情况以及您是否指定了 --force=true 参数:

集群状态 --force 参数 vmrumtime-force-disable 注释 行为
没有虚拟机 不适用 不适用 停用 VM Runtime on GDC。
现有虚拟机 True 正确 删除所有正在运行的虚拟机和相关资源。停用 VM Runtime on GDC。
True 错误 删除所有正在运行的虚拟机和相关资源。停用 VM Runtime on GDC。
False 正确 提示删除正在运行的虚拟机和相关资源。删除所有正在运行的虚拟机后,停用 VM Runtime on GDC。
False 错误 请勿删除任何正在运行的现有虚拟机。不删除 VM Runtime on GDC。bmctl 命令会返回错误。

VM Runtime on GDC 预检检查

使用 VM Runtime on GDC 和虚拟机之前,VM Runtime on GDC 预检检查会验证机器环境的一组前提条件。如果 VM Runtime on GDC 预检检查失败,则阻止创建虚拟机。当 spec.enabled 设置为 true 时,VM Runtime on GDC 预检检查会自动运行。

kubectl label nodes NODE_NAME "kubevm.io/VM-SkipSchedule"= --kubeconfig KUBECONFIG_PATH

当您执行以下任一操作时,VM Runtime on GDC 预检检查会运行:

  1. 启用 VM Runtime on GDC

  2. 启用 VM Runtime on GDC 功能,例如 useEmulation

  3. 升级集群

  4. 移除节点的 kubevm.io/VM-SkipSchedule 标签

  5. 通过运行 bmctl check vmruntimepfc --kubeconfig KUBECONFIG_PATH 命令或应用 VMRuntimePreflightCheck YAML 清单,独立创建 VM Runtime on GDC 预检检查对象。

您可以在最新的 VM Runtime on GDC 预检检查成功时启动虚拟机。如果预检检查失败,则系统会阻止创建虚拟机,并且您会收到预检检查错误。

验证预检检查成功

要验证预检检查是否成功,请运行以下命令:

  1. 查找上次执行的预检检查:

    kubectl get vmruntimepfc -n vm-system --kubeconfig KUBECONFIG_PATH
    

    输出应如下所示:

    NAME                                                             PASS    AGE
    vmruntime-preflight-check-6ee61513-ea5d-4340-9374-90396cac129e   false   42s
    vmruntime-preflight-check-f8d71751-a01c-471e-bab5-3370fc2addd5   true    21s
    
  2. 要查找预检检查的状态,请运行以下命令:

    kubectl get vmruntime vmruntime -o yaml --kubeconfig KUBECONFIG_PATH
    
    ...
      preflightCheckSummary:
      preflightCheckSummary:
        featureStatuses:
          CPU:
            passed: true
          KVM:
            passed: true
        preflightCheckName: vmruntime-preflight-check-f8d71751-a01c-471e-bab5-3370fc2addd5
        preflightCheckPassed: true
    ...
    

调试预检检查失败

如果预检检查失败,请执行以下步骤进行调试:

  1. 查找上次执行的预检检查。

    kubectl get vmruntimepfc -n vm-system
    
  2. 如需了解详情,请查看该预检检查的状态。

    kubectl get vmruntimepfc -n vm-system \
        vmruntime-preflight-check-6ee61513-ea5d-4340-9374-90396cac129e -o yaml \
        --kubeconfig KUBECONFIG_PATH
    
    ...
    status:
    checks:
      worker-0--52229ee15841099-22c41577139a7b8c.lab.anthos:
        passed: false
        results:
        - checkName: CPU
          passed: true
        - checkName: KVM
          message: |
            command terminated with exit code 1
            ls: /mnt/dev/kvm: No such file or directory
          passed: false
    ...
    
  3. 解决此问题并再次运行 VM Runtime on GDC 预检检查。下面显示了一个 VMRuntimePreflightCheck YAML 清单示例:

    apiVersion: vm.cluster.gke.io/v1
    kind: VMRuntimePreflightCheck
    metadata:
      name: vmruntime-preflight-check-manual
      namespace: vm-system
    

后续步骤