Wednesday, September 16, 2026

How to make the qemu image as worker node in kubernetes ?

--Gemini.Google.Com Result

To convert a QEMU disk image (such as .qcow2 or .raw) into a running Kubernetes worker node, you must configure the underlying OS inside the image, boot the Virtual Machine using QEMU/KVM, and join it to an existing Kubernetes control plane.

Phase 1: Configure the QEMU Base Image

Before starting the QEMU VM, update or customize the guest operating system (e.g., using cloud-init or virt-customize):

  • Disable Swap: Kubernetes requires swap space to be turned off.

    Bash
    sudo swapoff -a
    # Remove or comment out any swap lines in /etc/fstab
    sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
    
  • Enable Kernel Modules & Sysctl settings: Load overlay and br_netfilter modules required for container networking.

    Bash
    cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
    overlay
    br_netfilter
    EOF
    
    sudo modprobe overlay
    sudo modprobe br_netfilter
    
    cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-iptables  = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    net.ipv4.ip_forward                 = 1
    EOF
    
    sudo sysctl --system
    
  • Install Container Runtime (e.g., containerd):

    Bash
    sudo apt-get update && sudo apt-get install -y containerd
    sudo mkdir -p /etc/containerd
    containerd config default | sudo tee /etc/containerd/config.toml
    # Set SystemdCgroup to true in /etc/containerd/config.toml
    sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
    sudo systemctl restart containerd
    
  • Install Kubernetes Tools (kubelet & kubeadm):

    Bash
    sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl
    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
    echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
    sudo apt-get update
    sudo apt-get install -y kubelet kubeadm
    sudo apt-mark hold kubelet kubeadm
    
Phase 2: Launch the QEMU VM

Boot the .qcow2 image using QEMU/KVM with sufficient vCPUs, RAM, and bridged/TAP networking so it can communicate with the Control Plane:

Bash
qemu-system-x86_64 \
  -enable-kvm \
  -m 2048 \
  -smp 2 \
  -hda /path/to/your-worker-image.qcow2 \
  -netdev tap,id=net0,ifname=tap0,script=no,downscript=no \
  -device virtio-net-pci,netdev=net0 \
  -nographic
Phase 3: Join the Worker Node to the Cluster

  1. Get the join command from your Kubernetes Control Plane node:

    Bash
    kubeadm token create --print-join-command
    
  2. SSH into the booted QEMU virtual machine and execute the output command as root:

    Bash
    sudo kubeadm join <CONTROL_PLANE_IP>:6443 \
      --token <TOKEN> \
      --discovery-token-ca-cert-hash sha256:<HASH>
    
  3. Verify the Node: On your control plane, check that the node has registered:
    Bash
    kubectl get nodes