2.5. 在 GCP 上创建计算机器设置

您可以在 Google Cloud Platform (GCP)上的 OpenShift Container Platform 集群中创建不同的计算机器集来满足特定目的。例如,您可以创建基础架构机器集和相关的机器,以便将支持型工作负载转移到新机器上。

重要

您只能在 Machine API 操作的集群中使用高级机器管理和扩展功能。具有用户置备的基础架构的集群需要额外的验证和配置才能使用 Machine API。

具有基础架构平台类型 none 的集群无法使用 Machine API。即使附加到集群的计算机器安装在支持该功能的平台上,也会应用这个限制。在安装后无法更改此参数。

要查看集群的平台类型,请运行以下命令:

$ oc get infrastructure cluster -o jsonpath='{.status.platform}'

2.5.1. GCP 上计算机器设置自定义资源的 YAML 示例

此 YAML 示例定义了一个在 Google Cloud Platform (GCP)中运行的计算机器集,并创建通过 node-role.kubernetes.io/<role>: "" 标记的节点。

在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <role> 则是要添加的节点标签。

apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  labels:
    machine.openshift.io/cluster-api-cluster: <infrastructure_id> 1
  name: <infrastructure_id>-w-a
  namespace: openshift-machine-api
spec:
  replicas: 1
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: <infrastructure_id>
      machine.openshift.io/cluster-api-machineset: <infrastructure_id>-w-a
  template:
    metadata:
      creationTimestamp: null
      labels:
        machine.openshift.io/cluster-api-cluster: <infrastructure_id>
        machine.openshift.io/cluster-api-machine-role: <role> 2
        machine.openshift.io/cluster-api-machine-type: <role>
        machine.openshift.io/cluster-api-machineset: <infrastructure_id>-w-a
    spec:
      metadata:
        labels:
          node-role.kubernetes.io/<role>: ""
      providerSpec:
        value:
          apiVersion: gcpprovider.openshift.io/v1beta1
          canIPForward: false
          credentialsSecret:
            name: gcp-cloud-credentials
          deletionProtection: false
          disks:
          - autoDelete: true
            boot: true
            image: <path_to_image> 3
            labels: null
            sizeGb: 128
            type: pd-ssd
          gcpMetadata: 4
          - key: <custom_metadata_key>
            value: <custom_metadata_value>
          kind: GCPMachineProviderSpec
          machineType: n1-standard-4
          metadata:
            creationTimestamp: null
          networkInterfaces:
          - network: <infrastructure_id>-network
            subnetwork: <infrastructure_id>-worker-subnet
          projectID: <project_name> 5
          region: us-central1
          serviceAccounts:
          - email: <infrastructure_id>-w@<project_name>.iam.gserviceaccount.com
            scopes:
            - https://www.googleapis.com/auth/cloud-platform
          tags:
            - <infrastructure_id>-worker
          userDataSecret:
            name: worker-user-data
          zone: us-central1-a
1
其中 <infrastructure_id> 是基础架构 ID,它基于您在置备集群时设定的集群 ID。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取基础架构 ID:
$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster
2
对于 <node>,指定要添加的节点标签。
3
指定当前计算机器集中使用的镜像的路径。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取镜像的路径:
$ oc -n openshift-machine-api \
    -o jsonpath='{.spec.template.spec.providerSpec.value.disks[0].image}{"\n"}' \
    get machineset/<infrastructure_id>-worker-a

要使用 GCP Marketplace 镜像,请指定要使用的功能:

  • OpenShift Container Platform: https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-ocp-48-x86-64-202210040145
  • OpenShift Platform Plus: https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-opp-48-x86-64-202206140145
  • OpenShift Kubernetes Engine: https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-oke-48-x86-64-202206140145
4
可选:以 key:value 对的形式指定自定义元数据。有关用例,请参阅 GCP 文档,以查看设置自定义元数据
5
对于 <project_name>,请指定用于集群的 GCP 项目的名称。

2.5.2. 创建计算机器集

除了安装程序创建的计算机器集外,您还可以创建自己的来动态管理您选择的特定工作负载的机器计算资源。

先决条件

  • 部署一个 OpenShift Container Platform 集群。
  • 安装 OpenShift CLI(oc)。
  • 以具有 cluster-admin 权限的用户身份登录 oc

流程

  1. 创建一个包含计算机器集自定义资源(CR)示例的新 YAML 文件,并将其命名为 <file_name>.yaml

    确保设置 <clusterID><role> 参数值。

  2. 可选:如果您不确定要为特定字段设置哪个值,您可以从集群中检查现有计算机器集:

    1. 要列出集群中的计算机器集,请运行以下命令:

      $ oc get machinesets -n openshift-machine-api

      输出示例

      NAME                                DESIRED   CURRENT   READY   AVAILABLE   AGE
      agl030519-vplxk-worker-us-east-1a   1         1         1       1           55m
      agl030519-vplxk-worker-us-east-1b   1         1         1       1           55m
      agl030519-vplxk-worker-us-east-1c   1         1         1       1           55m
      agl030519-vplxk-worker-us-east-1d   0         0                             55m
      agl030519-vplxk-worker-us-east-1e   0         0                             55m
      agl030519-vplxk-worker-us-east-1f   0         0                             55m

    2. 要查看特定计算机器集自定义资源 (CR) 的值,请运行以下命令:

      $ oc get machineset <machineset_name> \
        -n openshift-machine-api -o yaml

      输出示例

      apiVersion: machine.openshift.io/v1beta1
      kind: MachineSet
      metadata:
        labels:
          machine.openshift.io/cluster-api-cluster: <infrastructure_id> 1
        name: <infrastructure_id>-<role> 2
        namespace: openshift-machine-api
      spec:
        replicas: 1
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-cluster: <infrastructure_id>
            machine.openshift.io/cluster-api-machineset: <infrastructure_id>-<role>
        template:
          metadata:
            labels:
              machine.openshift.io/cluster-api-cluster: <infrastructure_id>
              machine.openshift.io/cluster-api-machine-role: <role>
              machine.openshift.io/cluster-api-machine-type: <role>
              machine.openshift.io/cluster-api-machineset: <infrastructure_id>-<role>
          spec:
            providerSpec: 3
              ...

      1
      集群基础架构 ID。
      2
      默认节点标签。
      注意

      对于具有用户置备的基础架构的集群,计算机器集只能创建 workerinfra 类型机器。

      3
      计算机器设置 CR 的 <providerSpec> 部分中的值是特定于平台的。有关 CR 中的 <providerSpec> 参数的更多信息,请参阅您的供应商计算机器设置 CR 配置示例。
  3. 运行以下命令来创建 MachineSet CR:

    $ oc create -f <file_name>.yaml

验证

  • 运行以下命令,查看计算机器集列表:

    $ oc get machineset -n openshift-machine-api

    输出示例

    NAME                                DESIRED   CURRENT   READY   AVAILABLE   AGE
    agl030519-vplxk-infra-us-east-1a    1         1         1       1           11m
    agl030519-vplxk-worker-us-east-1a   1         1         1       1           55m
    agl030519-vplxk-worker-us-east-1b   1         1         1       1           55m
    agl030519-vplxk-worker-us-east-1c   1         1         1       1           55m
    agl030519-vplxk-worker-us-east-1d   0         0                             55m
    agl030519-vplxk-worker-us-east-1e   0         0                             55m
    agl030519-vplxk-worker-us-east-1f   0         0                             55m

    当新的计算机器集可用时,DESIREDCURRENT 的值会匹配。如果 compute 机器集不可用,请等待几分钟,然后再次运行命令。

2.5.3. 使用计算机器集配置持久磁盘类型

您可以通过编辑计算机器设置 YAML 文件来配置计算机器的持久磁盘类型。

有关持久性磁盘类型、兼容性、区域可用性和限制的更多信息,请参阅 GCP Compute Engine 文档有关持久性磁盘的信息。

步骤

  1. 在文本编辑器中,打开现有计算机器集的 YAML 文件,或创建新的计算机器。
  2. 编辑 providerSpec 字段中的以下行:

    providerSpec:
      value:
        disks:
          type: <pd-disk-type> 1
    1
    指定磁盘持久性类型。有效值为 pd-ssdpd-standardpd-balanced。默认值为 pd-standard

验证

  • 在 Google Cloud 控制台中,查看计算机器集部署的机器的详情,并验证 Type 字段是否与配置的磁盘类型匹配。

2.5.4. 将机器部署为可抢占虚拟机实例的机器集

您可以通过创建一个在 GCP 上运行的计算机器集来节约成本,该 MachineSet 将机器部署为非保障的虚拟机实例。抢占虚拟机实例使用了超额的 Compute Engine 容量,且比一般实例的成本要低。您可以将抢占虚拟机实例用于可容许中断的工作负载,如批处理或无状态工作负载、横向可扩展工作负载。

GCP Compute Engine 可随时终止可抢占的虚拟机实例。Compute Engine 向用户发送抢占通知,表示会在 30 秒内发生中断。当 Compute Engine 发出抢占通知时,OpenShift Container Platform 开始从受影响的实例中删除工作负载。如果实例没有停止,则 ACPI G3 Mechanical Off 信号会在 30 秒后发送到操作系统。然后,抢占虚拟机实例由 Compute Engine 转换为 TERMINATED 状态。

使用抢占虚拟机实例时可能会出现中断,理由如下:

  • 有系统或维护事件
  • 提供的抢占虚拟机实例减少
  • 该实例为抢占虚拟机实例到达分配的 24 小时期限的结束

当 GCP 终止一个实例时,在可抢占虚拟机实例节点上运行的终止处理器会删除机器资源。为了满足计算机器集副本数量,计算机器会创建一个请求抢占虚拟机实例的机器。

2.5.4.1. 使用计算机器集创建抢占虚拟机实例

您可以通过在计算机器设置 YAML 文件中添加 preemptible,在 GCP 上启动抢占虚拟机实例。

流程

  • providerSpec 字段中添加以下行:

    providerSpec:
      value:
        preemptible: true

    如果 preemptible 被设置为 true,则在实例启动后,机器将被标记为 interruptable-instance

2.5.5. 为计算机器设置启用客户管理的加密密钥

Google Cloud Platform(GCP)Compute Engine 允许用户提供加密密钥来加密磁盘上的数据。密钥用于对数据加密密钥进行加密,而不是加密客户的数据。默认情况下,Compute Engine 使用 Compute Engine 密钥加密这些数据。

您可以使用 Machine API 使用客户管理的密钥启用加密。您必须首先创建 KMS 密钥并为服务帐户分配正确的权限。需要 KMS 密钥名称、密钥环名称和位置来允许服务帐户使用您的密钥。

注意

如果您不想将专用服务帐户用于 KMS 加密,则使用 Compute Engine 默认服务帐户。如果没有使用专用服务帐户,则必须授予默认服务帐户权限来访问密钥。Compute Engine 默认服务帐户名称遵循 service-<project_number>@compute-system.iam.gserviceaccount.com 模式。

流程

  1. 使用您的 KMS 密钥名称、密钥环名称和位置运行以下命令,允许特定服务帐户使用您的 KMS 密钥,并为服务帐户授予正确的 IAM 角色:

    gcloud kms keys add-iam-policy-binding <key_name> \
      --keyring <key_ring_name> \
      --location <key_ring_location> \
      --member "serviceAccount:service-<project_number>@compute-system.iam.gserviceaccount.com” \
      --role roles/cloudkms.cryptoKeyEncrypterDecrypter
  2. 在计算机器设置的 YAML 文件中的 providerSpec 字段中配置加密密钥。例如:

    providerSpec:
      value:
        # ...
        disks:
        - type:
          # ...
          encryptionKey:
            kmsKey:
              name: machine-encryption-key 1
              keyRing: openshift-encrpytion-ring 2
              location: global 3
              projectID: openshift-gcp-project 4
            kmsKeyServiceAccount: openshift-service-account@openshift-gcp-project.iam.gserviceaccount.com 5
    1
    用于磁盘加密的客户管理的加密密钥名称。
    2
    KMS 密钥所属的 KMS 密钥环的名称。
    3
    KMS 密钥环存在的 GCP 位置。
    4
    可选:存在 KMS 密钥环的项目 ID。如果没有设置项目 ID,则会使用创建计算机器设置的 compute 机器集 projectID
    5
    可选:用于给定 KMS 密钥加密请求的服务帐户。如果没有设置服务帐户,则使用 Compute Engine 默认服务帐户。

    当使用更新的 providerSpec 对象配置创建新机器后,磁盘加密密钥就会使用 KMS 密钥加密。

2.5.6. 为计算机器设置启用 GPU 支持

Google Cloud Platform(GCP)Compute Engine 允许用户在虚拟机实例中添加 GPU。得益于访问 GPU 资源的工作负载可在启用了此功能的计算机器上更好地执行。GCP 上的 OpenShift Container Platform 支持 A2 和 N1 机器集中的 NVIDIA GPU 模型。

表 2.1. 支持的 GPU 配置

型号名称GPU 类型机器类型 [1]

NVIDIA A100

nvidia-tesla-a100

  • a2-highgpu-1g
  • a2-highgpu-2g
  • a2-highgpu-4g
  • a2-highgpu-8g
  • a2-megagpu-16g

NVIDIA K80

nvidia-tesla-k80

  • n1-standard-1
  • n1-standard-2
  • n1-standard-4
  • n1-standard-8
  • n1-standard-16
  • n1-standard-32
  • n1-standard-64
  • n1-standard-96
  • n1-highmem-2
  • n1-highmem-4
  • n1-highmem-8
  • n1-highmem-16
  • n1-highmem-32
  • n1-highmem-64
  • n1-highmem-96
  • n1-highcpu-2
  • n1-highcpu-4
  • n1-highcpu-8
  • n1-highcpu-16
  • n1-highcpu-32
  • n1-highcpu-64
  • n1-highcpu-96

NVIDIA P100

nvidia-tesla-p100

NVIDIA P4

nvidia-tesla-p4

NVIDIA T4

nvidia-tesla-t4

NVIDIA V100

nvidia-tesla-v100

  1. 有关机器类型的更多信息,包括规格、兼容性、区域可用性和限制,请参阅 GCP Compute Engine 文档,有关 N1 机器集A2 计算机系列GPU 区域以及区域可用性

您可以使用 Machine API 定义要用于实例的 GPU。

您可以在 N1 计算机序列中配置机器,以使用其中一个支持的 GPU 类型进行部署。A2 计算机系列中的机器附带关联的 GPU,无法使用客户机加速器。

注意

不支持用于图形工作负载的 GPU。

流程

  1. 在文本编辑器中,打开现有计算机器集的 YAML 文件,或创建新的计算机器。
  2. 在计算机器设置 YAML 文件中的 providerSpec 字段中指定 GPU 配置。请参见以下有效配置示例:

    A2 机器集配置示例:

      providerSpec:
        value:
          machineType: a2-highgpu-1g 1
          onHostMaintenance: Terminate 2
          restartPolicy: Always 3

    1
    指定机器类型。确保在 A2 机器集中包含机器类型。
    2
    在使用 GPU 支持时,您必须将 HostMaintenance 设置为 终止
    3
    为计算机器设置部署的机器指定重启策略。允许的值是 AlwaysNever

    N1 机器集配置示例:

    providerSpec:
      value:
        gpus:
        - count: 1 1
          type: nvidia-tesla-p100 2
        machineType: n1-standard-1 3
        onHostMaintenance: Terminate 4
        restartPolicy: Always 5

    1
    指定要附加到机器的 GPU 数。
    2
    指定要附加到机器的 GPU 类型。确保机器类型和 GPU 类型兼容。
    3
    指定机器类型。确保机器类型和 GPU 类型兼容。
    4
    在使用 GPU 支持时,您必须将 HostMaintenance 设置为 终止
    5
    为计算机器设置部署的机器指定重启策略。允许的值是 AlwaysNever

2.5.7. 将 GPU 节点添加到现有 OpenShift Container Platform 集群中

您可以复制并修改默认计算机器集配置,以便为 GPU 云供应商创建启用了 GPU 的机器集和机器。

下表列出了经过验证的实例类型:

实例类型NVIDIA GPU 加速器最大 GPU 数架构

a2-highgpu-1g

A100

1

x86

n1-standard-4

T4

1

x86

流程

  1. 制作现有 MachineSet 的副本。
  2. 在新副本中,在 metadata.name 中更改机器集名称,并在 machine.openshift.io/cluster-api-machineset 的两个实例中更改机器集名称。
  3. 更改实例类型,将以下两行添加到新复制的 MachineSet

    machineType: a2-highgpu-1g
    onHostMaintenance: Terminate

    a2-highgpu-1g.json 文件示例

    {
        "apiVersion": "machine.openshift.io/v1beta1",
        "kind": "MachineSet",
        "metadata": {
            "annotations": {
                "machine.openshift.io/GPU": "0",
                "machine.openshift.io/memoryMb": "16384",
                "machine.openshift.io/vCPU": "4"
            },
            "creationTimestamp": "2023-01-13T17:11:02Z",
            "generation": 1,
            "labels": {
                "machine.openshift.io/cluster-api-cluster": "myclustername-2pt9p"
            },
            "name": "myclustername-2pt9p-worker-gpu-a",
            "namespace": "openshift-machine-api",
            "resourceVersion": "20185",
            "uid": "2daf4712-733e-4399-b4b4-d43cb1ed32bd"
        },
        "spec": {
            "replicas": 1,
            "selector": {
                "matchLabels": {
                    "machine.openshift.io/cluster-api-cluster": "myclustername-2pt9p",
                    "machine.openshift.io/cluster-api-machineset": "myclustername-2pt9p-worker-gpu-a"
                }
            },
            "template": {
                "metadata": {
                    "labels": {
                        "machine.openshift.io/cluster-api-cluster": "myclustername-2pt9p",
                        "machine.openshift.io/cluster-api-machine-role": "worker",
                        "machine.openshift.io/cluster-api-machine-type": "worker",
                        "machine.openshift.io/cluster-api-machineset": "myclustername-2pt9p-worker-gpu-a"
                    }
                },
                "spec": {
                    "lifecycleHooks": {},
                    "metadata": {},
                    "providerSpec": {
                        "value": {
                            "apiVersion": "machine.openshift.io/v1beta1",
                            "canIPForward": false,
                            "credentialsSecret": {
                                "name": "gcp-cloud-credentials"
                            },
                            "deletionProtection": false,
                            "disks": [
                                {
                                    "autoDelete": true,
                                    "boot": true,
                                    "image": "projects/rhcos-cloud/global/images/rhcos-412-86-202212081411-0-gcp-x86-64",
                                    "labels": null,
                                    "sizeGb": 128,
                                    "type": "pd-ssd"
                                }
                            ],
                            "kind": "GCPMachineProviderSpec",
                            "machineType": "a2-highgpu-1g",
                            "onHostMaintenance": "Terminate",
                            "metadata": {
                                "creationTimestamp": null
                            },
                            "networkInterfaces": [
                                {
                                    "network": "myclustername-2pt9p-network",
                                    "subnetwork": "myclustername-2pt9p-worker-subnet"
                                }
                            ],
                            "preemptible": true,
                            "projectID": "myteam",
                            "region": "us-central1",
                            "serviceAccounts": [
                                {
                                    "email": "myclustername-2pt9p-w@myteam.iam.gserviceaccount.com",
                                    "scopes": [
                                        "https://www.googleapis.com/auth/cloud-platform"
                                    ]
                                }
                            ],
                            "tags": [
                                "myclustername-2pt9p-worker"
                            ],
                            "userDataSecret": {
                                "name": "worker-user-data"
                            },
                            "zone": "us-central1-a"
                        }
                    }
                }
            }
        },
        "status": {
            "availableReplicas": 1,
            "fullyLabeledReplicas": 1,
            "observedGeneration": 1,
            "readyReplicas": 1,
            "replicas": 1
        }
    }

  4. 运行以下命令,查看现有节点、机器和机器集。请注意,每个节点都是带有特定 GCP 区域和 OpenShift Container Platform 角色的机器定义实例。

    $ oc get nodes

    输出示例

    NAME                                                             STATUS     ROLES                  AGE     VERSION
    myclustername-2pt9p-master-0.c.openshift-qe.internal             Ready      control-plane,master   8h      v1.25.4+77bec7a
    myclustername-2pt9p-master-1.c.openshift-qe.internal             Ready      control-plane,master   8h      v1.25.4+77bec7a
    myclustername-2pt9p-master-2.c.openshift-qe.internal             Ready      control-plane,master   8h      v1.25.4+77bec7a
    myclustername-2pt9p-worker-a-mxtnz.c.openshift-qe.internal       Ready      worker                 8h      v1.25.4+77bec7a
    myclustername-2pt9p-worker-b-9pzzn.c.openshift-qe.internal       Ready      worker                 8h      v1.25.4+77bec7a
    myclustername-2pt9p-worker-c-6pbg6.c.openshift-qe.internal       Ready      worker                 8h      v1.25.4+77bec7a
    myclustername-2pt9p-worker-gpu-a-wxcr6.c.openshift-qe.internal   Ready      worker                 4h35m   v1.25.4+77bec7a

  5. 运行以下命令,查看 openshift-machine-api 命名空间中存在的机器和机器集。每个计算机器集都与 GCP 区域的不同可用区关联。安装程序会在可用区之间自动负载平衡计算机器。

    $ oc get machinesets -n openshift-machine-api

    输出示例

    NAME                               DESIRED   CURRENT   READY   AVAILABLE   AGE
    myclustername-2pt9p-worker-a       1         1         1       1           8h
    myclustername-2pt9p-worker-b       1         1         1       1           8h
    myclustername-2pt9p-worker-c       1         1                             8h
    myclustername-2pt9p-worker-f       0         0                             8h

  6. 运行以下命令,查看 openshift-machine-api 命名空间中存在的机器。您只能为每个集合配置一个计算机器,但您可以扩展计算机器集,以便在特定地区和区中添加节点。

    $ oc get machines -n openshift-machine-api | grep worker

    输出示例

    myclustername-2pt9p-worker-a-mxtnz       Running   n2-standard-4   us-central1   us-central1-a   8h
    myclustername-2pt9p-worker-b-9pzzn       Running   n2-standard-4   us-central1   us-central1-b   8h
    myclustername-2pt9p-worker-c-6pbg6       Running   n2-standard-4   us-central1   us-central1-c   8h

  7. 运行以下命令,复制现有计算 MachineSet 定义并将结果输出到 JSON 文件。这将是启用了 GPU 的计算机器集定义的基础。

    $ oc get machineset myclustername-2pt9p-worker-a -n openshift-machine-api -o json  > <output_file.json>
  8. 编辑 JSON 文件,对新 MachineSet 定义进行以下更改:

    • 通过在 metadata.name 中以及在两个 machine.openshift.io/cluster-api-machineset 实例中插入子字符串 gpu 来重新命名集群集名称
    • 将新 MachineSet 定义的 machineType 更改为 a2-highgpu-1g,其中包括 NVIDIA A100 GPU。

      jq .spec.template.spec.providerSpec.value.machineType ocp_4.12_machineset-a2-highgpu-1g.json
      
      "a2-highgpu-1g"

      <output_file.json> 文件被保持为 ocp_4.12_machineset-a2-highgpu-1g.json

  9. 更新 ocp_4.12_machineset-a2-highgpu-1g.json 中的以下字段:

    • .metadata.name 更改为包含 gpu 的名称。
    • 更改 .spec.selector.matchLabels["machine.openshift.io/cluster-api-machineset"],以匹配新的 .metadata.name
    • 更改 .spec.template.metadata.labels["machine.openshift.io/cluster-api-machineset"],以匹配新的 .metadata.name
    • .spec.template.spec.providerSpec.value.MachineType 更改为 a2-highgpu-1g
    • machineType 下添加以下行: `"onHostMaintenance": "Terminate".例如:

      "machineType": "a2-highgpu-1g",
      "onHostMaintenance": "Terminate",
  10. 要验证您的更改,请运行以下命令对原始计算定义和新的 GPU 节点定义执行 diff

    $ oc get machineset/myclustername-2pt9p-worker-a -n openshift-machine-api -o json | diff ocp_4.12_machineset-a2-highgpu-1g.json -

    输出示例

    15c15
    <         "name": "myclustername-2pt9p-worker-gpu-a",
    ---
    >         "name": "myclustername-2pt9p-worker-a",
    25c25
    <                 "machine.openshift.io/cluster-api-machineset": "myclustername-2pt9p-worker-gpu-a"
    ---
    >                 "machine.openshift.io/cluster-api-machineset": "myclustername-2pt9p-worker-a"
    34c34
    <                     "machine.openshift.io/cluster-api-machineset": "myclustername-2pt9p-worker-gpu-a"
    ---
    >                     "machine.openshift.io/cluster-api-machineset": "myclustername-2pt9p-worker-a"
    59,60c59
    <                         "machineType": "a2-highgpu-1g",
    <                         "onHostMaintenance": "Terminate",
    ---
    >                         "machineType": "n2-standard-4",

  11. 运行以下命令,从定义文件创建启用了 GPU 的计算机器集:

    $ oc create -f ocp_4.12_machineset-a2-highgpu-1g.json

    输出示例

    machineset.machine.openshift.io/myclustername-2pt9p-worker-gpu-a created

验证

  1. 运行以下命令,查看您创建的机器集:

    $ oc -n openshift-machine-api get machinesets | grep gpu

    MachineSet 副本数被设置为 1,以便自动创建新的 Machine 对象。

    输出示例

    myclustername-2pt9p-worker-gpu-a   1         1         1       1           5h24m

  2. 运行以下命令,查看创建机器集的 Machine 对象:

    $ oc -n openshift-machine-api get machines | grep gpu

    输出示例

    myclustername-2pt9p-worker-gpu-a-wxcr6   Running   a2-highgpu-1g   us-central1   us-central1-a   5h25m

注意

请注意,不需要为节点指定命名空间。节点定义是在集群范围之内。

2.5.8. 部署 Node Feature Discovery Operator

创建启用了 GPU 的节点后,您需要发现启用了 GPU 的节点,以便调度它。为此,请安装 Node Feature Discovery (NFD) Operator。NFD Operator 识别节点中的硬件设备功能。它解决了在基础架构节点中识别和目录硬件资源的一般问题,以便 OpenShift Container Platform 可以使用它们。

流程

  1. 在 OpenShift Container Platform 控制台中,从 OperatorHub 安装 Node Feature Discovery Operator。
  2. 将 NFD Operator 安装到 OperatorHub 后,从已安装的 Operator 列表中选择 Node Feature Discovery,然后选择 Create instance。这会在 openshift-nfd 命名空间中安装 nfd-masternfd-worker pod,每个计算节点一个 nfd-worker pod。
  3. 运行以下命令验证 Operator 是否已安装并正在运行:

    $ oc get pods -n openshift-nfd

    输出示例

    NAME                                       READY    STATUS     RESTARTS   AGE
    
    nfd-controller-manager-8646fcbb65-x5qgk    2/2      Running 7  (8h ago)   1d

  4. 浏览到控制台中的已安装的 Oerator,再选择 Create Node Feature Discovery
  5. 选择 Create 以构建 NFD 自定义资源。这会在 openshift-nfd 命名空间中创建 NFD pod,为硬件资源和目录轮询 OpenShift Container Platform 节点。

验证

  1. 构建成功后,运行以下命令来验证 NFD pod 是否在每个节点上运行:

    $ oc get pods -n openshift-nfd

    输出示例

    NAME                                       READY   STATUS      RESTARTS        AGE
    nfd-controller-manager-8646fcbb65-x5qgk    2/2     Running     7 (8h ago)      12d
    nfd-master-769656c4cb-w9vrv                1/1     Running     0               12d
    nfd-worker-qjxb2                           1/1     Running     3 (3d14h ago)   12d
    nfd-worker-xtz9b                           1/1     Running     5 (3d14h ago)   12d

    NFD Operator 使用厂商 PCI ID 来识别节点的硬件。NVIDIA 使用 PCI ID 10de

  2. 运行以下命令,查看 NFD Operator 发现的 NVIDIA GPU:

    $ oc describe node ip-10-0-132-138.us-east-2.compute.internal | egrep 'Roles|pci'

    输出示例

    Roles: worker
    
    feature.node.kubernetes.io/pci-1013.present=true
    
    feature.node.kubernetes.io/pci-10de.present=true
    
    feature.node.kubernetes.io/pci-1d0f.present=true

    10de 会出现在启用了 GPU 的节点的节点功能列表中。这意味着 NFD Operator 可以正确地识别启用了 GPU 的 MachineSet 的节点。