Skip to content

Machine Config

Machine Config Operator Documentation

Creating a Machine Configuration File

  1. Base64 encode the content for inclusion in a MachineConfig:

    echo -n "mysecretvalue" | base64
    
  2. Place the encoded value after base64, in the MachineConfig (the base64 string bXlzZWNyZXR2YWx1ZQ== decodes to mysecretvalue):

    apiVersion: machineconfiguration.openshift.io/v1
    kind: MachineConfig
    metadata:
      name: 99-worker-example
      labels:
        machineconfiguration.openshift.io/role: worker
    spec:
      config:
        ignition:
          version: 3.5.0
        storage:
          files:
          - path: /etc/file.conf
            mode: 0644
            overwrite: true
            contents:
              source: data:text/plain;charset=utf-8;base64,bXlzZWNyZXR2YWx1ZQ==
    
  3. Apply:

    Warning

    Applying a MachineConfig that changes file content, systemd units, or other non-SSH configuration will cause the Machine Config Operator to drain and reboot every node in the target pool. Ensure the cluster has sufficient capacity. To defer the reboot, pause the pool first: oc patch mcp worker --type merge -p '{"spec":{"paused":true}}'. Unpause after: oc patch mcp worker --type merge -p '{"spec":{"paused":false}}'.

    oc apply -f 99-worker-example.yaml
    

Use a File

base64 -w0 myfile.txt
CONTENT=$(base64 -w0 /path/to/myfile.conf)

cat <<EOF
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  labels:
    machineconfiguration.openshift.io/role: worker
  name: 99-worker-myfile
spec:
  config:
    ignition:
      version: 3.5.0
    storage:
      files:
      - path: /etc/myfile.conf
        mode: 0644
        overwrite: true
        contents:
          source: data:text/plain;base64,${CONTENT}
EOF

To decode/verify:

echo "$CONTENT" | base64 -d

Creating a Machine Configuration File with Butane

Butane transpiles human-readable configs into MachineConfig resources, avoiding manual base64 encoding.

  1. Install Butane:

    curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/butane/latest/butane
    chmod +x butane
    sudo mv butane /usr/local/bin/
    
  2. Write a Butane config — create 99-worker-example.bu:

    variant: openshift
    version: 4.22.0  # Must match your OCP minor version (e.g., 4.23.0 for OCP 4.23)
    metadata:
      name: 99-worker-example
      labels:
        machineconfiguration.openshift.io/role: worker
    storage:
        files:
          - path: /etc/file.conf
            mode: 0644
            overwrite: true
            contents:
              inline: |
                mysecretvalue
    
  3. Transpile to MachineConfig:

    butane 99-worker-example.bu -o 99-worker-example.yaml
    
  4. Apply:

    oc apply -f 99-worker-example.yaml
    

Using a Local File

Instead of inline, reference a local file:

variant: openshift
version: 4.22.0  # Must match your OCP minor version
metadata:
  name: 99-worker-example
  labels:
    machineconfiguration.openshift.io/role: worker
storage:
  files:
    - path: /etc/file.conf
      mode: 0644
      overwrite: true
      contents:
        local: file.conf
butane 99-worker-example.bu --files-dir . -o 99-worker-example.yaml