Provisioning KubeVirt VMs as Bare Metal with Metal3 and KubeVirtBMC

Share

Bringing Bare-Metal Provisioning to KubeVirt VMs with Metal3 and KubeVirtBMC

In a previous post, we introduced KubeVirtBMC, a tool that provides virtual BMC endpoints for KubeVirt VMs. We demonstrated basic interactions using raw IPMI and Redfish commands. While useful for testing, the real potential of KubeVirtBMC is unlocked when it’s integrated with established bare-metal provisioning tools like Metal3.

This post provides a complete, end-to-end guide to using Metal3 to manage and provision KubeVirt VMs through KubeVirtBMC, treating them exactly like physical servers. Every step is detailed so you can replicate the setup in your own environment.

Why Choose Metal3 for This Workflow?

Metal3 is a CNCF Incubating project that integrates bare-metal host management into the Kubernetes ecosystem. It leverages OpenStack Ironic to handle critical tasks such as hardware inspection, boot device configuration, and writing OS images to disks.

The core of Metal3 is the BareMetalHost custom resource. You define the desired state—including BMC address, credentials, and target image—and Metal3 manages the rest. The typical BareMetalHost lifecycle is shown below:

Figure 1: Create BareMetalHost cycle

Metal3 is designed to communicate with a BMC via IPMI or Redfish. Physical servers have this hardware built-in. KubeVirt VMs don’t—unless you provide one using KubeVirtBMC.

Demo Environment Overview

The diagram below illustrates the architecture we’ll build.

Figure 2: High-level overview of the demo environment

The entire system runs within a single Kubernetes cluster. Metal3 manages BareMetalHost resources that point to the virtual BMC endpoints created by KubeVirtBMC. When Metal3 instructs Ironic to power on a host or attach a boot image, Ironic sends Redfish requests to the KubeVirtBMC pod. This pod translates the requests into Kubernetes API calls to manage the KubeVirt VM. From Metal3’s perspective, it is interacting with a standard BMC.

Prerequisites

Before starting, ensure you have the following:

  • A Kubernetes cluster with virtualization support (either nested virtualization or on bare metal).
  • KubeVirt installed and operational.
  • A storage provider for VirtualMachine disks.
  • kubectl, helm, and kustomize installed on your local machine.

If you need help setting up a cluster, the instructions in the previous post cover using KubeVirt CI or Harvester.

Step 1: Install cert-manager

Both KubeVirtBMC and Metal3 components depend on cert-manager for their webhook certificates.

helm upgrade --install cert-manager oci://quay.io/jetstack/charts/cert-manager 
    --namespace=cert-manager 
    --create-namespace 
    --set=crds.enabled=true

Step 2: Install KubeVirtBMC

KubeVirtBMC is installed using its Helm chart.

helm upgrade --install kubevirtbmc kubevirtbmc 
    --repo=https://charts.kubevirtbmc.io 
    --namespace=kubevirtbmc-system 
    --create-namespace

Verify the installation:

$ kubectl get pods -n kubevirtbmc-system
NAME                                      READY   STATUS    RESTARTS   AGE
kubevirtbmc-controller-manager-xxxxx      1/1     Running   0          30s

Step 3: Create a KubeVirt VM with a Virtual BMC

We’ll create a VirtualMachine to act as our simulated bare-metal host. It needs a disk, a network interface, and must start in a powered-off state to allow Metal3 to manage its lifecycle from the beginning.

First, create a PVC for the VM’s root disk:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: metal3-demo-vm-disk
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
EOF

Create the VirtualMachine with `runStrategy: Halted` to keep it powered off:

cat <<EOF | kubectl apply -f -
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: metal3-demo-vm
  namespace: default
spec:
  runStrategy: Halted
  template:
    spec:
      domain:
        cpu:
          cores: 4
        memory:
          guest: 8Gi
        devices:
          disks:
          - name: rootdisk
            disk:
              bus: virtio
          - name: cdrom
            cdrom:
              bus: sata
          interfaces:
          - name: default
            macAddress: "02:00:00:00:00:01"
            bridge: {}
        firmware:
          bootloader:
            efi:
              secureBoot: false
      networks:
      - name: default
        pod: {}
      volumes:
      - name: rootdisk
        persistentVolumeClaim:
          claimName: metal3-demo-vm-disk
EOF

Key configuration details:

  • **runStrategy: Halted** ensures the VM is off until Metal3 is ready to power it on.
  • The **cdrom device** is required for KubeVirtBMC to attach ISO images via Redfish virtual media later.
  • The **macAddress** is explicitly set to `02:00:00:00:00:01`. Each BareMetalHost requires a `bootMACAddress` that corresponds to a real NIC on the machine. Pinning this value avoids issues with discovering a randomly generated MAC address.
  • We use **BIOS firmware** for simplicity. Switch to UEFI if your provisioning image demands it.

Next, create the VirtualMachineBMC resource and a Secret for its credentials:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
  name: demo-bmc-secret
  namespace: default
stringData:
  username: admin
  password: password
---
apiVersion: bmc.kubevirt.io/v1beta1
kind: VirtualMachineBMC
metadata:
  name: demo-bmc
  namespace: default
spec:
  virtualMachineRef:
    name: metal3-demo-vm
  authSecretRef:
    name: demo-bmc-secret
EOF

Wait for the BMC to be ready and note its ClusterIP:

kubectl wait --for=condition=Ready virtualmachinebmcs demo-bmc 
--timeout=60s
$ kubectl get virtualmachinebmcs demo-bmc
NAME       VIRTUALMACHINE   SECRET           CLUSTERIP       READY
demo-bmc   metal3-demo-vm   demo-bmc-secret  10.96.xxx.xxx   True

Find the name of the generated Service:

$ kubectl get services -l kubevirt.io/virtualmachinebmc-name=demo-bmc
NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
metal3-demo-vm-virtbmc   ClusterIP   10.96.xxx.xxx           80/TCP,623/UDP   58s

The BMC service is accessible at `metal3-demo-vm-virtbmc.default.svc.cluster.local` from within the cluster.

Step 4: Install the Metal3 Stack

Metal3 comprises two main operators: the Bare Metal Operator (BMO) and Ironic. We’ll deploy Ironic using the Ironic Standalone Operator (IrSO), the recommended method for new setups.

Install the Ironic Standalone Operator

Install IrSO from the latest code, as the `ironic.spec.networking.disableHostNetwork` field was added recently and may not be in an official release yet.

git clone https://github.com/metal3-io/ironic-standalone-operator.git
cd ironic-standalone-operator
make install deploy

kubectl -n ironic-standalone-operator-system wait --for=condition=Available 
    deploy/ironic-standalone-operator-controller-manager 
    --timeout=120s

Deploy Ironic

Following the Metal3 quickstart pattern, we’ll use a kustomization to deploy Ironic and BMO together. First, create the namespace and TLS certificates:

kubectl create ns baremetal-operator-system

We’ll generate self-signed certificates using cert-manager for Ironic.

Apply the cert-manager resources
cat <<EOF | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: selfsigned-issuer
  namespace: baremetal-operator-system
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: ironic-cacert
  namespace: baremetal-operator-system
spec:
  commonName: ironic-ca
  isCA: true
  issuerRef:
    kind: Issuer
    name: selfsigned-issuer
  secretName: ironic-cacert
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: ca-issuer
  namespace: baremetal-operator-system
spec:
  ca:
    secretName: ironic-cacert
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: ironic-cert
  namespace: baremetal-operator-system
spec:
  secretTemplate:
    labels:
      environment.metal3.io/ironic-standalone-operator: "true"
  dnsNames:
  - ironic.baremetal-operator-system.svc
  - ironic.baremetal-operator-system.svc.cluster.local
  issuerRef:
    kind: Issuer
    name: ca-issuer
  secretName: ironic-cert
EOF

It’s also best practice to create credentials for the Ironic API endpoints explicitly. If not provided, IrSO will generate random ones.

Apply the credentials Secret
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
  labels:
    environment.metal3.io/ironic-standalone-operator: "true"
  name: ironic-credentials
  namespace: baremetal-operator-system
type: kubernetes.io/basic-auth
stringData:
  username: ironic
  password: supersecret
EOF

Now, create the Ironic custom resource. Since this demo uses virtual media for provisioning, the configuration is minimal.

Apply the Ironic resource
cat <<EOF | kubectl apply -f -
apiVersion: ironic.metal3.io/v1alpha1
kind: Ironic
metadata:
  name: ironic
  namespace: baremetal-operator-system
spec:
  apiCredentialsName: ironic-credentials
  networking:
    disableHostNetwork: true
  tls:
    certificateName: ironic-cert
    disableVirtualMediaTLS: true
  version: "37.0"
EOF

A crucial detail is setting `.spec.tls.disableVirtualMediaTLS` to `true`. This prevents dynamically generated images from being hosted on a TLS-protected HTTP server. At the time of writing, neither KubeVirtBMC nor the underlying CDI (Containerized Data Importer) can properly handle the certificates created by Ironic or skip certificate verification.

IrSO will use the credentials you provided and create the Ironic pod. Wait for it to be ready:

kubectl -n baremetal-operator-system wait --for=condition=Ready 
    ironic/ironic 
    --timeout=300s

**Note:** We are not configuring DHCP or a provisioning network here. Ironic will attach boot images via the Redfish API (virtual media) instead of PXE booting, so those components are unnecessary.

Install the Bare Metal Operator

Clone the baremetal-operator repository and create a kustomization overlay.

git clone https://github.com/metal3-io/baremetal-operator.git
cd baremetal-operator

Create an overlay to configure BMO to connect to the in-cluster Ironic instance.

Configure the BMO overlay
mkdir -p config/overlays/kubevirtbmc-demo

cat > config/overlays/kubevirtbmc-demo/kustomization.yaml < config/default/ironic.env <

Deploy BMO:

kustomize build config/overlays/kubevirtbmc-demo | kubectl apply -f -

kubectl -n baremetal-operator-system wait --for=condition=Available 
    deploy/baremetal-operator-controller-manager 
    --timeout=120s

Verify all Metal3 components are running:

$ kubectl get pods -n baremetal-operator-system
NAME                                                      READY   STATUS    RESTARTS   AGE
baremetal-operator-controller-manager-xxxxx               1/1     Running   0          60s
ironic-service-xxxxx                                      4/4     Running   0          2m

Step 5: Register the VM as a BareMetalHost

Now we create a BareMetalHost resource pointing to the KubeVirtBMC endpoint. Metal3 treats it like any standard Redfish interface, unaware it’s a virtual BMC.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
  name: metal3-demo-vm-bmc-secret
  namespace: default
stringData:
  username: admin
  password: password
---
apiVersion: metal3.io/v1alpha1
kind: BareMetalHost
metadata:
  name: metal3-demo-vm
  namespace: default
spec:
  online: true
  bootMACAddress: "02:00:00:00:00:01"
  bmc:
    address: redfish-virtualmedia+http://metal3-demo-vm-virtbmc.default.svc.cluster.local:80/redfish/v1/Systems/1
    credentialsName: metal3-demo-vm-bmc-secret
    disableCertificateVerification: true
  rootDeviceHints:
    deviceName: /dev/vda
EOF

Important details on the `bmc.address` field:

  • The **`redfish-virtualmedia`** driver tells Ironic to use Redfish with virtual media support (ISO boot) instead of PXE. See the supported hardware page for other driver types.
  • The **`+http`** suffix explicitly selects plain HTTP because the BMC pod doesn’t serve HTTPS by default. Without this, Ironic defaults to HTTPS and the connection will fail.
  • The host portion, **`metal3-demo-vm-virtbmc.default.svc.cluster.local:80`**, is the in-cluster Service created by KubeVirtBMC.
  • **`/redfish/v1/Systems/1`** is the Redfish system path exposed by KubeVirtBMC.

The `bootMACAddress` matches the pinned MAC address from the VirtualMachine spec.

Watch the BareMetalHost go through its lifecycle:

$ kubectl get bmh metal3-demo-vm -w
NAME             STATE          CONSUMER   ONLINE   ERROR   AGE
metal3-demo-vm   registering                true             5s
metal3-demo-vm   inspecting                 true             30s
metal3-demo-vm   preparing                  true             9m30s
metal3-demo-vm   available                  true             9m31s

During the **registering** phase, Ironic verifies the BMC credentials via Redfish. During **inspecting**, Ironic boots the IPA (Ironic Python Agent) ramdisk on the VM to discover hardware details like CPU, memory, and NICs. Once complete, the host becomes **available** for provisioning.

You can inspect the discovered hardware inventory:

kubectl get bmh metal3-demo-vm -o 
jsonpath='{.status.hardware}'

Step 6: Provision the Host with an OS Image

Now we provision the VM with an OS. We’ll use the `live-iso` approach, which instructs Ironic to boot the host from an ISO image via virtual media. This mode is ideal for integrating with site-specific installers, as Metal3 simply boots the ISO and leaves the installation to the process running inside it.

kubectl patch bmh metal3-demo-vm --type=merge -p '
{
  "spec": {
    "image": {
      "url": "https://releases.ubuntu.com/resolute/ubuntu-26.04-live-server-amd64.iso",
      "format": "live-iso"
    }
  }
}'

**Note:** The `live-iso` format doesn’t require a checksum; Metal3 does not enforce checksums for these images.

If you prefer to write a disk image directly, you can use a qcow2 file with a checksum:

kubectl patch bmh metal3-demo-vm --type=merge -p '
{
 "spec": {
   "image": {
     "url": "https://cloud-images.ubuntu.com/resolute/current/resolute-server-cloudimg-amd64.img",
     "checksum": "https://cloud-images.ubuntu.com/resolute/current/SHA256SUMS",
     "checksumType": "auto",
     "format": "qcow2"
   }
 }
}'

Watch the provisioning progress:

$ kubectl get bmh metal3-demo-vm -w
NAME             STATE          CONSUMER   ONLINE   ERROR   AGE
metal3-demo-vm   provisioning              true             5m
metal3-demo-vm   provisioned               true             12m

Here’s what happens behind the scenes:

Graphic 3: behind the scenes

The entire flow is transparent. Metal3 and Ironic use standard Redfish calls. KubeVirtBMC translates them into Kubernetes API operations on the VirtualMachine resource, and KubeVirt handles the actual VM lifecycle.

Step 7: Verify and Clean Up

Check the final state:

$ kubectl get bmh
NAME             STATE         CONSUMER   ONLINE   ERROR   AGE
metal3-demo-vm   provisioned              true             15m

$ kubectl get vm
NAME             AGE   STATUS    READY
metal3-demo-vm   20m   Running   True 

To deprovision the host and return it to the available pool:

kubectl patch bmh metal3-demo-vm --type=json 
   -p '[{"op": "remove", "path": "/spec/image"}]'

To clean up all demo resources:

kubectl delete bmh metal3-demo-vm
kubectl delete virtualmachinebmc demo-bmc
kubectl delete secret demo-bmc-secret metal3-demo-vm-bmc-secret
kubectl delete vm metal3-demo-vm
kubectl delete pvc metal3-demo-vm-disk

Common Pitfalls and Troubleshooting Tips

Here are a few issues you might encounter:

  • MAC address mismatch. The `bootMACAddress` in the BareMetalHost must match a real interface on the VM. We pinned it to `02:00:00:00:00:01` in the VirtualMachine spec to avoid this. If forgotten, KubeVirt generates a random MAC, and Ironic can’t match the host during inspection.
  • HTTP vs HTTPS. KubeVirtBMC serves Redfish over plain HTTP by default. Use `redfish-virtualmedia+http://` in the BMC address. Without the `+http` suffix, Ironic defaults to HTTPS, and the connection will fail during registration.
  • Virtual media vs network boot. The `redfish-virtualmedia` driver boots images via ISO attachment, which means no PXE, DHCP, or provisioning network is needed. If you use the standard `redfish` driver, you’ll need to set up DHCP and configure Ironic’s networking settings, which we’ll cover in a future post.
  • Ironic host networking. By default, IrSO enables host networking for Ironic. The Ironic pod must be reachable from the IPA ramdisk running inside the VMs. In a single cluster, this works out of the box. In this article, we disable host networking to rely on in-cluster DNS for routing traffic to the Ironic service. For more complex topologies, you may need to adjust this.
  • Cross-cluster scenarios. If Metal3 runs in a different cluster than KubeVirt, you can expose the KubeVirtBMC Services externally using Ingress or NodePort. Just update the BMC address in the BareMetalHost accordingly.

Why This Integration Matters

This setup demonstrates that KubeVirtBMC is useful beyond simple API testing. It integrates with production-grade bare-metal provisioning workflows:

  • CI/CD for bare-metal tools. Projects like Metal3 and Ironic can use KubeVirtBMC to run integration tests on VMs instead of maintaining physical server fleets.
  • Faster developer feedback loops. Developers building bare-metal features can iterate quickly with VMs that start in seconds.
  • Accessible training and demos. Showcasing Metal3 no longer requires a rack of servers. A single Kubernetes cluster with KubeVirt is sufficient.

What’s Next for KubeVirtBMC

The KubeVirtBMC project is actively developed, with ongoing work to improve Redfish compatibility and expand its feature set. To follow progress or contribute, visit the GitHub repository.

If you find this useful, or encounter an issue replicating it, please open an issue or leave a comment. Your feedback is crucial for the project’s growth.

Happy provisioning!

Read more