Updated on 2025-04-27 GMT+08:00

Enabling VM Runtime

  1. Preparations

    1. Download kubectl and kubeconfig.
      1. Download the client kubectl and user configuration file kubeconfig from the cluster console and copy them to the /home directory on the client.
      2. Log in to your client and configure kubectl.
        cd /home
        chmod +x kubectl
        mv -f kubectl /usr/local/bin
        mkdir -p $HOME/.kube
        mv -f kubeconfig.json $HOME/.kube/config
        kubectl config use-context internal
      3. View the Kubernetes cluster information.
        kubectl cluster-info
    2. Obtain the latest KubeVirt version.
      export VERSION=v1.5.0

  2. Add aggregation layer certificate forwarding on the API server of the cluster.

    Access the /var/paas/kubernetes/manifests directory on a master node in the cluster and add the following parameters to the kube-apiserver.manifest file to modify the API server configuration:

    --proxy-client-key-file=/srv/kubernetes/aggregation-tls.key
    --proxy-client-cert-file=/srv/kubernetes/aggregation-tls.crt

  3. Install kubevirt-operator.

    Run the following command in the /home directory on the client:
    kubectl create -f "https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-operator.yaml"
    If the installation is successful, the following information is displayed:
    namespace/kubevirt created
    customresourcedefinition.apiextensions.k8s.io/kubevirts.kubevirt.io created
    priorityclass.scheduling.k8s.io/kubevirt-cluster-critical created
    clusterrole.rbac.authorization.k8s.io/kubevirt.io:operator created
    serviceaccount/kubevirt-operator created
    role.rbac.authorization.k8s.io/kubevirt-operator created
    rolebinding.rbac.authorization.k8s.io/kubevirt-operator-rolebinding created
    clusterrole.rbac.authorization.k8s.io/kubevirt-operator created
    clusterrolebinding.rbac.authorization.k8s.io/kubevirt-operator created
    deployment.apps/virt-operator created

  4. Install the KubeVirt CR.

    1. Download and modify the CR file of KubeVirt.
      1. Download the CR file of KubeVirt.
        curl -L https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-cr.yaml -o kubevirt-cr-cce.yaml
      2. Add the following content to the kubevirt-cr-cce.yaml file:
        apiVersion: kubevirt.io/v1
        kind: KubeVirt
        metadata:
          name: kubevirt
          namespace: kubevirt
        spec:
          certificateRotateStrategy: {}
          configuration:
            developerConfiguration: {}
          customizeComponents:
            patches:
              - resourceType: DaemonSet
                resourceName: virt-handler
                patch: '{"spec": {"template": {"spec": {
                    "volumes": [
                      {"name": "kubelet-pods", "hostPath": {"path": "/mnt/paas/kubernetes/kubelet/pods"}},
                      {"name": "kubelet-pods-shortened", "hostPath": {"path": "/mnt/paas/kubernetes/kubelet/pods"}},
                      {"name": "device-plugin", "hostPath": {"path": "/mnt/paas/kubernetes/kubelet/device-plugins"}}
                    ],
                    "containers": [{
                      "name": "virt-handler",
                      "volumeMounts": [
                        {"name": "kubelet-pods", "mountPath": "/mnt/paas/kubernetes/kubelet/pods", "mountPropagation": "Bidirectional"},
                        {"name": "device-plugin", "mountPath": "/mnt/paas/kubernetes/kubelet/device-plugins"}
                      ]
                    }]
                  }}}}'
                type: strategic
            flags:
              handler:
                kubelet-pods-dir: /mnt/paas/kubernetes/kubelet/pods
                kubelet-root: /mnt/paas/kubernetes/kubelet
      3. Save the modification and run the following command:
        kubectl create -f ./kubevirt-cr-cce.yaml
        If the command is executed successfully, the following information is displayed:
        kubevirt.kubevirt.io/kubevirt created
        kubevirt.kubevirt.io/kubevirt created
    2. Wait for the installation is successful.
      watch -n 1 kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.phase}"

      If the status changes from Deploying to Deployed, the installation is successful.

  5. Confirm the support for hardware virtualization.

    1. Install libvirt-client.
      sudo apt-get install libvirt-client
    2. Check whether the server supports virtualization.
      virt-host-validate qemu
      • If the following information is displayed, the server does not support hardware virtualization:
        QEMU: Checking for hardware virtualization: FAIL (Only emulated CPUs are available, performance will be significantly limited)
      • If FAIL is displayed, you can enable the KubeVirt software simulation. Note that the performance will deteriorate significantly.
        kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true}}}}'

  6. Install virtctl.

    Install the KubeVirt command line tool virtctl.

    VERSION=$(kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.observedKubeVirtVersion}")
    ARCH=$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/') || windows-amd64.exe
    echo ${VERSION}-${ARCH}
    curl -L -o virtctl https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-${ARCH}
    chmod +x virtctl
    sudo install virtctl /usr/local/bin

You can take the preceding steps to enable VM Runtime in on-premises clusters. If you encounter any problems during the installation, see the official documents of KubeVirt or contact Huawei Cloud technical support.