πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Configuration intermediate ⏱ 15 minutes K8s 1.28+

Set Kernel Parameters via MachineConfig

Tune kernel sysctl parameters on OpenShift nodes using MachineConfig. Set networking, memory, and performance sysctls on RHCOS.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Create a MachineConfig with sysctl settings in the kernelArguments field or via a file at /etc/sysctl.d/99-custom.conf. The MCO drains, applies, and reboots each node sequentially.

The Problem

Your Kubernetes workloads need custom kernel parameters β€” higher net.core.somaxconn for high-traffic Services, larger vm.max_map_count for Elasticsearch, or tuned net.ipv4.tcp_* settings for network performance. On RHCOS, you can’t SSH in and run sysctl -w β€” changes must go through MachineConfig.

The Solution

Method 1: Sysctl File via MachineConfig

# Create sysctl config
cat > /tmp/99-custom-sysctl.conf << 'EOF'
# Network performance
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_reuse = 1

# Memory (for Elasticsearch, etc.)
vm.max_map_count = 262144

# File descriptors
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288
EOF

# Base64 encode
SYSCTL_B64=$(base64 -w0 /tmp/99-custom-sysctl.conf)

# Create MachineConfig
cat > 99-worker-sysctl.yaml << EOF
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  name: 99-worker-sysctl
  labels:
    machineconfiguration.openshift.io/role: worker
spec:
  config:
    ignition:
      version: 3.2.0
    storage:
      files:
        - path: /etc/sysctl.d/99-custom.conf
          mode: 0644
          overwrite: true
          contents:
            source: "data:text/plain;charset=utf-8;base64,${SYSCTL_B64}"
EOF

oc apply -f 99-worker-sysctl.yaml

Method 2: Kernel Arguments (Boot Parameters)

apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  name: 99-worker-kernel-args
  labels:
    machineconfiguration.openshift.io/role: worker
spec:
  kernelArguments:
    - "hugepagesz=2M"
    - "hugepages=1024"
    - "intel_iommu=on"
    - "iommu=pt"

Verify After Rollout

# Check sysctl values
oc debug node/worker-1 -- chroot /host sysctl net.core.somaxconn vm.max_map_count
# net.core.somaxconn = 65535
# vm.max_map_count = 262144

# Check kernel arguments
oc debug node/worker-1 -- chroot /host cat /proc/cmdline
graph TD
    A[Identify needed sysctl] --> B{Runtime or boot param?}
    B -->|Runtime sysctl| C[Create /etc/sysctl.d/99-custom.conf]
    B -->|Boot parameter| D[Use kernelArguments field]
    C --> E[MachineConfig with file]
    D --> F[MachineConfig with kernelArguments]
    E --> G[MCO drains + reboots nodes]
    F --> G
    G --> H[Verify with sysctl or /proc/cmdline]

Common Issues

Sysctl Value Not Persisting

Runtime sysctls in /etc/sysctl.d/ are loaded by systemd-sysctl.service on boot. If the file exists but values aren’t set, check:

oc debug node/worker-1 -- chroot /host systemctl status systemd-sysctl

Invalid Kernel Parameter

If you set an invalid parameter, the MachineConfig applies but the sysctl is ignored. Always test values first.

Best Practices

  • Use /etc/sysctl.d/99-custom.conf for runtime sysctls β€” the 99- prefix ensures it overrides defaults
  • Use kernelArguments for boot-time parameters (hugepages, IOMMU, etc.)
  • Apply to specific MCPs β€” GPU nodes may need different sysctls than general workers
  • Test with oc debug before creating the MachineConfig
  • Document why each sysctl is set β€” comments in the conf file help future operators

Key Takeaways

  • RHCOS is immutable β€” use MachineConfig for all kernel tuning
  • Runtime sysctls go in /etc/sysctl.d/ files, boot params use kernelArguments
  • MCO rolls out changes node-by-node with drain and reboot
  • Always verify after rollout with sysctl or /proc/cmdline
#openshift #machineconfig #kernel #sysctl #tuning
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens