Skip to content

OpenShift - (BMH) Bare Metal Hosts

OCP 4.19 - Creating a compute machine set on bare metal

Associating BMH with MachineSets

The HostSelector specifies matching criteria for labels on BareMetalHosts.

There be dragons here...

As of OpenShift docs 4.19, there is no usable example or official documentation of this feature. Have fun! 😄

Using matchLabels

Below is an example of using hostSelector in combination with matchLabels to allow a specific BMH to be targeted for use in provisioning a MachineSet.

Label the BMH with a label of machine.openshift.io/zone: us-east-1a

Note

The label can be any key: value pair

apiVersion: metal3.io/v1alpha1
kind: BareMetalHost
metadata:
  name: vm-00
  namespace: openshift-machine-api
  labels:
    machine.openshift.io/zone: us-east-1a
spec:
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  name: worker-0
  namespace: openshift-machine-api
spec:
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-machineset: worker-0
  template:
    metadata:
      labels:
        machine.openshift.io/region: us-east-1
        machine.openshift.io/zone: us-east-1a
    spec:
      providerSpec:
        value:
          hostSelector:
            matchLabels:
              machine.openshift.io/zone: us-east-1a

Using matchExpressions

Warning

This does not appear to work. YMMV.

More detailed label selection should be possible using common operators.

See HostSelector

apiVersion: metal3.io/v1alpha1
kind: BareMetalHost
metadata:
  name: vm-00
  namespace: openshift-machine-api
  labels:
    machine.openshift.io/zone: us-east-1a
spec:
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  name: worker-0
  namespace: openshift-machine-api
spec:
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-machineset: worker-0
  template:
    metadata:
      labels:
        machine.openshift.io/region: us-east-1
        machine.openshift.io/zone: us-east-1a
    spec:
      providerSpec:
        value:
          hostSelector:
            matchExpressions:
              - key: machine.openshift.io/zone
                operator: Equals
                values:
                  - us-east-1a