9.17.11.5. Managing mediated devices
Before you can assign mediated devices to virtual machines, you must create the devices and expose them to the cluster. You can also reconfigure and remove mediated devices.
9.17.11.5.1. Creating and exposing mediated devices 링크 복사링크가 클립보드에 복사되었습니다!
As an administrator, you can create mediated devices and expose them to the cluster by editing the HyperConverged custom resource (CR). Before you edit the CR, explore a worker node to find the configuration values that are specific to your hardware devices.
Prerequisites
-
You installed the OpenShift CLI (
oc). - You enabled the Input-Output Memory Management Unit (IOMMU) driver.
If your hardware vendor provides drivers, you installed them on the nodes where you want to create mediated devices.
- If you use NVIDIA cards, you installed the NVIDIA GRID driver.
Procedure
Identify the name selector and resource name values for the mediated devices by exploring a worker node:
Start a debugging session with the worker node by using the
oc debugcommand. For example:$ oc debug node/node-11.redhat.comChange the root directory of the shell process to the file system of the host node by running the following command:
# chroot /hostNavigate to the
mdev_busdirectory and view its contents. Each subdirectory name is a PCI address of a physical GPU. For example:# cd sys/class/mdev_bus && lsExample output:
0000:4b:00.4Go to the directory for your physical device and list the supported mediated device types as defined by the hardware vendor. For example:
# cd 0000:4b:00.4 && ls mdev_supported_typesExample output:
nvidia-742 nvidia-744 nvidia-746 nvidia-748 nvidia-750 nvidia-752 nvidia-743 nvidia-745 nvidia-747 nvidia-749 nvidia-751 nvidia-753Select the mediated device type that you want to use and identify its name selector value by viewing the contents of its
namefile. For example:# cat nvidia-745/nameExample output:
NVIDIA A2-2Q
Open the
HyperConvergedCR in your default editor by running the following command:$ oc edit hyperconverged kubevirt-hyperconverged -n openshift-cnvCreate and expose the mediated devices by updating the configuration:
-
Create mediated devices by adding them to the
spec.mediatedDevicesConfigurationstanza. Expose the mediated devices to the cluster by adding the
mdevNameSelectorandresourceNamevalues to thespec.permittedHostDevices.mediatedDevicesstanza. TheresourceNamevalue is based on themdevNameSelectorvalue, but you use underscores instead of spaces.Example
HyperConvergedCR:apiVersion: hco.kubevirt.io/v1 kind: HyperConverged metadata: name: kubevirt-hyperconverged namespace: openshift-cnv spec: mediatedDevicesConfiguration: mediatedDeviceTypes: - nvidia-745 nodeMediatedDeviceTypes: - mediatedDeviceTypes: - nvidia-746 nodeSelector: kubernetes.io/hostname: node-11.redhat.com permittedHostDevices: mediatedDevices: - mdevNameSelector: NVIDIA A2-2Q resourceName: nvidia.com/NVIDIA_A2-2Q - mdevNameSelector: NVIDIA A2-4Q resourceName: nvidia.com/NVIDIA_A2-4Q # ...where:
mediatedDeviceTypes- Specifies global settings for the cluster and is required.
nodeMediatedDeviceTypes-
Specifies global configuration overrides for a specific node or group of nodes and is optional. Must be used with the global
mediatedDeviceTypesconfiguration. mediatedDeviceTypes-
Specifies an override to the global
mediatedDeviceTypesconfiguration for the specified nodes. Required if you usenodeMediatedDeviceTypes. nodeSelector-
Specifies the node selector and must include a
key:valuepair. Required if you usenodeMediatedDeviceTypes. mdevNameSelector- Specifies the mediated devices that map to this value on the host.
resourceName- Specifies the matching resource name that is allocated on the node.
-
Create mediated devices by adding them to the
- Save your changes and exit the editor.
Verification
Confirm that the virtual GPU is attached to the node by running the following command:
$ oc get node <node_name> -o json \ | jq '.status.allocatable \ | with_entries(select(.key | startswith("nvidia.com/"))) \ | with_entries(select(.value != "0"))'