Fixing Kubevirt networking not working on reboot

Published on , 165 words, 1 minutes to read

Turns out randomizing the MAC address on boot is a bad idea

When you use Ubuntu on Kubevirt like I do, rebooting a VM or manually rescheduling pods means that the MAC address in the VM changes. This makes Ubuntu's netplan very unhappy and will result in your VM not acquiring an IP address over DHCP. This is not good for uptime.

After searching the GitHub issue tracker, I found this comment from 2018 that suggested adding this netplan configuration file to the VM:

network:
  version: 2
  ethernets:
    id0:
      dhcp4: true
      match:
        name: enp*

This does the trick, so my minimal cloud-init config for Ubuntu on Kubevirt VM looks like this:

#cloud-config
hostname: noble
ssh_pwauth: True
disable_root: false

write_files:
  - encoding: b64
    content: bmV0d29yazoKICB2ZXJzaW9uOiAyCiAgZXRoZXJuZXRzOgogICAgaWQwOgogICAgICBkaGNwNDogdHJ1ZQogICAgICBtYXRjaDoKICAgICAgICBuYW1lOiBlbnAqCg==
    owner: root:root
    path: /etc/netplan/99-net-fix.yaml
    permissions: "0644"

users:
  - name: xe
    groups: [wheel]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
    ssh_import_id:
      - gh:xe

I've done reboot testing with my virtual machines and this seems to work consistently enough.


Facts and circumstances may have changed since publication. Please contact me before jumping to conclusions if something seems wrong or unclear.

Tags: