You can change the configuration of a virtual machine (VM) at any time after creation. On a powered-off machine, the changes apply right away, and on a running one Deckhouse Platform (DP) applies them differently depending on what exactly you changed.

Configuration block How it applies on a running VM
.metadata.labels Right away, and it propagates to the VM pod
.metadata.annotations Right away, and it propagates to the VM pod
.spec.liveMigrationPolicy Right away
.spec.runPolicy Right away
.spec.disruptions.restartApprovalMode Right away
.spec.affinity Right away in commercial DP editions, a restart is required in DP Open
.spec.nodeSelector Right away in commercial DP editions, a restart is required in DP Open
.spec.cpu.cores Without a restart if changing the number of cores without a restart is enabled in commercial DP editions, otherwise a restart is required
.spec.networks Adding and removing networks applies on a running VM if the guest OS supports attaching interfaces on the fly
Other .spec fields A restart is required

The following example shows how to change the configuration of a virtual machine:

  • Using the CLI
  • Using the web interface

The following example changes the number of cores.

  1. Check how many cores the guest OS sees now:

    d8 v ssh cloud@linux-vm --command "nproc"
    

    Example output:

    1
    
  2. Set the new number of cores:

    d8 k patch vm linux-vm --type merge -p '{"spec":{"cpu":{"cores":2}}}'
    
    # You can achieve the same result by editing the resource.
    d8 k edit vm linux-vm
    
  3. Verify that the change is accepted but not applied yet. The guest OS still sees one core, and the list of pending changes isn’t empty:

    d8 k get vm linux-vm -o jsonpath="{.status.restartAwaitingChanges}" | jq .
    

    Example output:

    [
      {
        "currentValue": 1,
        "desiredValue": 2,
        "operation": "replace",
        "path": "cpu.cores"
      }
    ]
    

    The NEED RESTART column shows the same:

    d8 k get vm linux-vm -o wide
    

    Example output:

    NAME       PHASE     UPTIME   CORES   COREFRACTION   MEMORY   NEED RESTART   AGENT   MIGRATABLE   NODE           IPADDRESS     AGE
    linux-vm   Running   5m16s    2       100%           1Gi      True           True    True         virtlab-pt-1   10.66.10.13   5m16s
    
  4. Restart the machine:

    d8 v restart linux-vm
    
  5. Check the result. After the restart, the .status.restartAwaitingChanges block is empty and the guest OS sees two cores:

    d8 v ssh cloud@linux-vm --command "nproc"
    

    Example output:

    2
    

By default, you confirm the restart. To make DP apply the changes itself, set the .spec.disruptions.restartApprovalMode parameter to Automatic:

spec:
  disruptions:
    restartApprovalMode: Automatic
  1. Go to the Projects tab and select the project you need.
  2. Go to VirtualizationVirtual machines.
  3. Select the VM you need from the list and click its name.
  4. Make the changes on the Configuration tab. If the machine has to be restarted, DP shows a warning and the list of pending changes.
  5. To make the changes apply without your confirmation, scroll down to the Life cycle section, enable the Auto-apply changes toggle, and click Save.

Changing the number of cores without a restart

You can change the number of cores of a running machine without rebooting it, if the change is applicable through live migration. Within the current CPU topology, you can both add and remove cores.

The feature is disabled by default. To enable it, an administrator adds HotplugCPUWithLiveMigration to the .spec.settings.featureGates parameter:

kind: ModuleConfig
metadata:
  name: virtualization
spec:
  settings:
    featureGates:
      - HotplugCPUWithLiveMigration

In the web interface, the same toggle is called Change CPU without reboot and is located in the Experimental features block on the System tab, in DeckhouseModulesvirtualizationConfiguration. Only a DP administrator has the rights for this.

When the feature is enabled and the new .spec.cpu.cores value stays within the current topology, DP applies the change by live migration. If the change requires a different topology, the machine has to be rebooted. The topology calculation rules are described in CPU topologies.

  • Using the CLI
  • Using the web interface

Set the new number of cores:

d8 k patch vm linux-vm --type merge -p '{"spec":{"cpu":{"cores":4}}}'
  1. Go to the Projects tab and select the project you need.
  2. Go to VirtualizationVirtual machines.
  3. Select the VM you need from the list and click its name.
  4. On the Configuration tab, in the Resources section, set the new value in the CPU cores field.
  5. Click the Save button that appears.

The guest OS doesn’t always bring new cores into service on its own, especially after a live migration. In Linux, a core is brought online through sysfs:

echo 1 > /sys/devices/system/cpu/cpu1/online

To make this happen automatically, add a udev rule:

cat <<'EOF' > /etc/udev/rules.d/99-hotplug-cpu.rules
SUBSYSTEM=="cpu",ACTION=="add",RUN+="/bin/sh -c '[ ! -e /sys$devpath/online ] || echo 1 > /sys$devpath/online'"
EOF

The cores brought into service appear in the output of nproc, cat /proc/cpuinfo, and top.

When you reduce the number of cores within the current topology, the distribution of cores across sockets is preserved.

Changing the amount of memory without a restart

You can increase the amount of memory of a running machine without rebooting it. Reducing it requires a restart.

The feature is disabled by default. To enable it, an administrator adds HotplugMemoryWithLiveMigration to the .spec.settings.featureGates parameter:

kind: ModuleConfig
metadata:
  name: virtualization
spec:
  settings:
    featureGates:
      - HotplugMemoryWithLiveMigration

In the web interface, the toggle is called Change memory without reboot and is located in the same place, in the Experimental features block of the module settings.

When the feature is enabled, the new .spec.memory.size value is greater than the current one, and the machine allows migration, DP applies the change by live migration. A restart is required if the memory is reduced, if the original size is less than 1 GiB, or if the machine can’t be migrated. Without a restart, memory grows up to 256 GiB, the ceiling built into the machine configuration at first start.

  • Using the CLI
  • Using the web interface

Set the new memory size:

d8 k patch vm linux-vm --type merge -p '{"spec":{"memory":{"size":"4Gi"}}}'
  1. Go to the Projects tab and select the project you need.
  2. Go to VirtualizationVirtual machines.
  3. Select the VM you need from the list and click its name.
  4. On the Configuration tab, in the Resources section, set the new value in the Memory size field.
  5. Click the Save button that appears.

As with cores, the guest OS may not bring new memory blocks into service on its own. In Linux, a block is brought online through sysfs, and the device name is visible in the lsmem output or in the /sys/bus/memory/devices/ directory:

echo 1 > /sys/bus/memory/devices/memoryXXX/online

To make this happen automatically, add a udev rule:

cat <<'EOF' > /etc/udev/rules.d/99-hotplug-memory.rules
SUBSYSTEM=="memory",ACTION=="add",DEVPATH=="/devices/system/memory/memory[0-9]*", TEST=="state", ATTR{state}!="online", ATTR{state}="online"
EOF

Additional resources