DEV Community

Florient DOGBE
Florient DOGBE

Posted on

Machine Config Operator: Changing OpenShift Node Config Without Bricking the Cluster

On OpenShift you do not ssh into a node and edit /etc/sysctl.conf. The OS is immutable (RHCOS), and the only supported way to change node state is to declare it in a MachineConfig object. The Machine Config Operator (MCO) then renders, distributes, and applies that change — draining and rebooting nodes one by one.

That machinery is excellent until the day you push a MachineConfig with a bad file path, an invalid Ignition version, or a kubelet setting that makes the kubelet refuse to start. Then the MCO does exactly what you told it to do, on every node of the pool, in sequence. Workers go NotReady in cascade, and because new nodes also boot from the same rendered config, autoscaling cannot save you either.

This article walks through the render cycle, the pools, the pause mechanism, and a concrete procedure to test and roll back a sysctl or kubelet change.

Context: what actually breaks

Three components matter:

  • machine-config-controller: watches MachineConfig and MachineConfigPool objects, merges all configs matching a pool into a single rendered config (rendered-worker-<hash>), and sets it as the pool's target.
  • machine-config-daemon (MCD): a DaemonSet pod on every node. It compares the node's currentConfig annotation to desiredConfig, cordons and drains the node, writes files and systemd units, then reboots.
  • machine-config-server (MCS): serves the rendered Ignition config on port 22623 to nodes booting for the first time.

Two consequences flow directly from this design. First, a bad rendered config is applied to every node in the pool, serially, with maxUnavailable: 1 by default — so you have a window to react, but it is measured in minutes. Second, that same rendered config is what new nodes consume at boot, so scaling out reproduces the breakage.

Also worth knowing: the control plane is a pool too. A MachineConfig labelled master reboots your API servers, etcd included.

The render cycle, step by step

# All MachineConfigs, including the rendered ones (prefixed rendered-)
oc get machineconfig --sort-by=.metadata.creationTimestamp

# Current target of each pool
oc get mcp -o custom-columns=NAME:.metadata.name,\
CONFIG:.spec.configuration.name,\
UPDATED:.status.conditions[?\(@.type==\"Updated\"\)].status,\
DEGRADED:.status.conditions[?\(@.type==\"Degraded\"\)].status
Enter fullscreen mode Exit fullscreen mode

The flow is: you create 99-worker-sysctl → the controller merges it with all other configs selected by the worker pool (ordering is lexicographic on the name, hence the 99- convention) → it produces rendered-worker-<newhash> → it patches mcp/worker.spec.configuration.name → each MCD sees desiredConfig != currentConfig and starts the drain/write/reboot dance.

Per node, you can follow it with annotations:

oc get nodes -l node-role.kubernetes.io/worker -o custom-columns=\
NAME:.metadata.name,\
CURRENT:.metadata.annotations.machineconfiguration\\.openshift\\.io/currentConfig,\
DESIRED:.metadata.annotations.machineconfiguration\\.openshift\\.io/desiredConfig,\
STATE:.metadata.annotations.machineconfiguration\\.openshift\\.io/state
Enter fullscreen mode Exit fullscreen mode

state goes Done → Working → Done, or Degraded when the MCD refuses or fails to apply.

Never edit a rendered-* object. It is regenerated from its sources; your edit will be reverted or will desynchronise the pool.

Writing a sysctl MachineConfig the safe way

Use Butane, not hand-written Ignition

Ignition files are base64 or URL-encoded data URLs. Writing them by hand is how you ship a config with a truncated payload. Use butane with the openshift variant, which generates a valid MachineConfig directly:

# 99-worker-sysctl.bu
variant: openshift
version: 4.15.0
metadata:
  name: 99-worker-sysctl
  labels:
    machineconfiguration.openshift.io/role: worker
storage:
  files:
    - path: /etc/sysctl.d/90-kube-net.conf
      mode: 0644
      overwrite: true
      contents:
        inline: |
          net.core.somaxconn=16384
          net.ipv4.neigh.default.gc_thresh1=8192
          net.ipv4.neigh.default.gc_thresh2=32768
          net.ipv4.neigh.default.gc_thresh3=65536
Enter fullscreen mode Exit fullscreen mode
butane 99-worker-sysctl.bu -o 99-worker-sysctl.yaml
oc apply -f 99-worker-sysctl.yaml --dry-run=server
Enter fullscreen mode Exit fullscreen mode

The generated manifest looks like this (note the Ignition version — 3.4.0 for OCP 4.14+; a version your cluster does not understand puts the pool straight into Degraded):

apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  name: 99-worker-sysctl
  labels:
    machineconfiguration.openshift.io/role: worker
spec:
  config:
    ignition:
      version: 3.4.0
    storage:
      files:
        - path: /etc/sysctl.d/90-kube-net.conf
          mode: 420
          overwrite: true
          contents:
            source: data:text/plain;charset=utf-8;base64,bmV0LmNvcmUuc29tYXhjb25uPTE2Mzg0Cg==
Enter fullscreen mode Exit fullscreen mode

The --dry-run=server call catches schema errors but not semantic ones: a sysctl key that does not exist on RHCOS will make systemd-sysctl log an error without blocking the boot, while a broken systemd unit with Before=kubelet.service absolutely will.

Avoid the reboot with a node disruption policy

By default, any file change triggers drain + reboot. Since OCP 4.17, NodeDisruptionPolicy is GA and lets you declare a cheaper action per path:

apiVersion: operator.openshift.io/v1
kind: MachineConfiguration
metadata:
  name: cluster
spec:
  nodeDisruptionPolicy:
    files:
      - path: /etc/sysctl.d/90-kube-net.conf
        actions:
          - type: Restart
            restart:
              serviceName: sysctl-custom.service
Enter fullscreen mode Exit fullscreen mode

This assumes you ship a oneshot unit that runs sysctl --system. Valid action types are Reboot, Drain, Reload, Restart, DaemonReload, Special and None. Anything not listed keeps the default Reboot. This is a huge latency win on large pools — and a huge risk if you declare None for a file that actually needs a reboot, because the node will then report Done while running the old behaviour. Declare None only for files consumed on demand (cron, logrotate, custom scripts).

KubeletConfig: a MachineConfig you do not write yourself

Never patch /etc/kubernetes/kubelet.conf via a raw MachineConfig. Use the KubeletConfig CRD; the MCO generates the corresponding MachineConfig (99-worker-generated-kubelet) for you:

apiVersion: machineconfiguration.openshift.io/v1
kind: KubeletConfig
metadata:
  name: worker-canary-tuning
spec:
  machineConfigPoolSelector:
    matchLabels:
      pools.operator.machineconfiguration.openshift.io/worker-canary: ""
  kubeletConfig:
    maxPods: 350
    kubeAPIQPS: 100
    kubeAPIBurst: 200
    systemReserved:
      cpu: 500m
      memory: 1Gi
    evictionHard:
      memory.available: "500Mi"
      nodefs.available: "10%"
Enter fullscreen mode Exit fullscreen mode

The pools.operator.machineconfiguration.openshift.io/<pool> label is added automatically by the MCO to every MachineConfigPool, so you can target pools without inventing your own labels. Two practical constraints: the cluster caps the number of KubeletConfig objects (10), and multiple CRs targeting the same pool are merged — overlapping fields produce results that are hard to reason about. One KubeletConfig per pool is the sane rule.

A malformed kubeletConfig (unknown field, bad unit in evictionHard) is partly caught by the operator, but values that are syntactically valid and semantically wrong — systemReserved.memory: 60Gi on a 64 GB node — will get through and make the kubelet fail to start. This is exactly the class of bug canary pools exist for.

Canary rollouts with a dedicated MachineConfigPool

Never test on the worker pool. Carve out one or two nodes:

oc label node ip-10-0-42-17.ec2.internal node-role.kubernetes.io/worker-canary=
Enter fullscreen mode Exit fullscreen mode
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfigPool
metadata:
  name: worker-canary
spec:
  maxUnavailable: 1
  machineConfigSelector:
    matchExpressions:
      - key: machineconfiguration.openshift.io/role
        operator: In
        values: [worker, worker-canary]
  nodeSelector:
    matchLabels:
      node-role.kubernetes.io/worker-canary: ""
Enter fullscreen mode Exit fullscreen mode

The matchExpressions with [worker, worker-canary] is the key detail: the canary pool inherits everything the worker pool gets, plus whatever you label worker-canary. The node leaves the worker pool automatically (a node belongs to exactly one pool; being in two pools degrades the MCO).

Validation loop after the change lands:

oc get mcp worker-canary -w

NODE=ip-10-0-42-17.ec2.internal
oc debug node/$NODE -- chroot /host sysctl net.core.somaxconn
oc debug node/$NODE -- chroot /host systemctl is-active kubelet
oc debug node/$NODE -- chroot /host journalctl -u kubelet --since "-10 min" -p err
oc get node $NODE -o jsonpath='{.status.allocatable.pods}{"\n"}'
Enter fullscreen mode Exit fullscreen mode

Only once the canary has run real workloads for a few hours do you remove the worker-canary restriction and let the change hit the full pool.

Pausing: the emergency brake and its expiry date

If you see a pool going sideways, the first reflex is to stop the rollout:

oc patch mcp/worker --type merge -p '{"spec":{"paused":true}}'
Enter fullscreen mode Exit fullscreen mode

The node currently being updated finishes; the others stay on their existing config. This buys you time to diagnose without losing the whole pool.

Caveats that bite people:

  • A paused pool also stops receiving certificate and CA bundle updates distributed by the MCO. Keep pauses to hours, not weeks, or you will eventually break kubelet-to-API-server authentication.
  • Pausing does not roll back the node already broken. It only stops propagation.
  • Pausing master blocks control-plane updates, including those pulled in by a cluster upgrade. Unpause before upgrading.

Reduce blast radius permanently with a conservative maxUnavailable on large pools (default is 1; people who set maxUnavailable: 25% to speed up upgrades are the ones who lose a quarter of their capacity at once).

Rolling back

Clean rollback

Deleting the offending object is enough. The controller re-renders the pool without it and the MCD reapplies:

oc delete machineconfig 99-worker-sysctl
oc patch mcp/worker --type merge -p '{"spec":{"paused":false}}'
oc get mcp worker -w
Enter fullscreen mode Exit fullscreen mode

Expect a second reboot cycle: the rollback is a config change like any other. Which is why pausing early matters — the fewer nodes that took the bad config, the fewer nodes need to be fixed.

To compare what actually changed between two renders:

oc get mc rendered-worker-a1b2c3 -o yaml > before.yaml
oc get mc rendered-worker-d4e5f6 -o yaml > after.yaml
diff -u before.yaml after.yaml
Enter fullscreen mode Exit fullscreen mode

Node stuck in Degraded

oc get mcp worker -o jsonpath='{.status.conditions[?(@.type=="NodeDegraded")].message}{"\n"}'
oc get node $NODE -o jsonpath='{.metadata.annotations.machineconfiguration\.openshift\.io/reason}{"\n"}'

oc logs -n openshift-machine-config-operator \
  -l k8s-app=machine-config-daemon -c machine-config-daemon --tail=100
Enter fullscreen mode Exit fullscreen mode

The most common cause is "unexpected on-disk state": someone modified a file by hand, so the MCD refuses to reconcile. After confirming the on-disk content is the one you want to keep, you can let it proceed:

oc debug node/$NODE
# inside the debug pod
chroot /host
touch /run/machine-config-daemon-force
exit
# then force the MCD to resync
oc delete pod -n openshift-machine-config-operator \
  -l k8s-app=machine-config-daemon --field-selector spec.nodeName=$NODE
Enter fullscreen mode Exit fullscreen mode

If the node no longer boots correctly because of an OS-level change, RHCOS keeps the previous deployment:

oc debug node/$NODE -- chroot /host rpm-ostree status
# from the serial console if the node is unreachable:
# rpm-ostree rollback && systemctl reboot
Enter fullscreen mode Exit fullscreen mode

Last resort on IPI clusters: delete the Machine object and let the MachineSet recreate the node from the (now fixed) rendered config.

Security best practices

  • Treat machineconfiguration.openshift.io write access as cluster-admin. Anyone who can create a MachineConfig can drop a systemd unit running as root on every node. Audit oc adm policy who-can create machineconfig and keep that list minimal.
  • Never put a secret in a MachineConfig. The object is cluster-scoped and readable by any principal with get on it, and its content ends up in plaintext (base64 is not encryption) inside the rendered config. Use Secret objects mounted by the workload, or an operator that provisions the material on the node.
  • Lock down ports 22623/22624. The machine-config-server serves the full node Ignition config, which includes bootstrap credentials. It must be reachable only from the node network — verify your security groups, load balancer listeners, and NetworkPolicy/egress rules.
  • Set restrictive file modes and ownership in Ignition: mode: 0600 and user: {name: root} for anything sensitive, never 0777.
  • Prefer oc debug node over SSH. Remove core SSH keys from your MachineConfigs where you can; every key you ship is a persistent root path onto every node that bypasses the API audit log.
  • Do not weaken SELinux. permissive in a MachineConfig is a cluster-wide downgrade that survives reboots and is easy to forget.
  • Scope allowedUnsafeSysctls (set via KubeletConfig) to a dedicated pool and taint those nodes; unsafe sysctls are namespaced-but-abusable escape surface.
  • GitOps everything. MachineConfigs go through a Git repository with mandatory review, rendered by Argo CD with sync waves, so that oc apply -f from a laptop is not how your node OS changes.

Key takeaways

  • The MCO is a reconciliation loop over the node OS: MachineConfig → rendered config → MCD → drain → reboot. Understand the chain and the failure modes stop being mysterious.
  • A pool is the blast radius. Create a worker-canary pool with a machineConfigSelector matching both worker and worker-canary, and validate there first — always.
  • Generate Ignition with butane, use KubeletConfig and ContainerRuntimeConfig CRDs instead of raw files, and never edit a rendered-* object.
  • oc patch mcp/worker --type merge -p '{"spec":{"paused":true}}' is your emergency brake; use it in the first minutes of an incident, and unpause within hours, not weeks.
  • Rollback is a oc delete machineconfig plus a second reboot cycle; for a node stuck in Degraded, go through oc debug node, the MCD logs, /run/machine-config-daemon-force, and rpm-ostree rollback as the last line of defence.
  • Keep maxUnavailable low, watch oc get mcp during any rollout, and treat node config changes with the same change-management discipline as a control-plane upgrade.

Top comments (0)