<button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">Version 1.12 </button>

- [Latest](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/latest/vm-runtime/edit-vm)
- [Version 1.16](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.16/vm-runtime/edit-vm.md.txt)
- [Earlier versions (unsupported)](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/getting-support.md.txt#version-support)

<br />

This document is intended for application owners that run Google Distributed Cloud.
This document shows you how to edit virtual machines (VMs) that run using
VM Runtime on Google Distributed Cloud. For example, you can edit resource allocation like
CPU and memory, or change the network a VM connects to.

You can modify any field in the `spec` section of a `VirtualMachine` resource.
You can also edit the labels for a VM. Other fields, such as the VM name
(`metadata.name`), can't be edited. Your VM must be in a `Stopped` state before
you edit the resource.

If your edits to the `VirtualMachine` resource contain errors when you save
them, the changes are rejected and you see a notification. Correct the
error(s) and try to save the `VirtualMachine` resource again. If your VM doesn't
start after you make changes, use the
`kubectl describe gvm VM_NAME` command to
view troubleshooting information and correct the error(s).

## Before you begin

To complete this document, you need access to the following resources:

- A VM that runs in one of your clusters. If needed, [create a VM in Google Distributed Cloud](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/quickstart.md.txt).
- The `virtctl` client tool installed as a plugin for `kubectl`. If needed, [install the virtctl client tool](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/quickstart.md.txt#install_the_virtctl_client_tool).

## Edit compute resources

If your compute workload demands change, you can update the number of virtual
CPUs and amount of virtual memory you assign to your VMs. To edit your compute
workloads, complete the following steps:

1. Stop the VM that you want to edit:

   ```bash
   kubectl virt stop VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you
   want to stop.
2. Use `kubectl` to edit the VM:

   ```bash
   kubectl edit gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you
   want to edit.
3. In your editor, update the compute resource values that you want to change.

   For example, the following sample `VirtualMachine` manifest shows that the VM
   resource has `2` vCPUs assigned:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: vm1
   spec:
     ...
     compute:
       cpu:
         vcpus: 2
   ...
   ```

   If you want to update the number of assigned vCPUs, change the value in your
   editor, as shown in the following example:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: vm1
   spec:
     ...
     compute:
       cpu:
         vcpus: 4
   ...
   ```
4. Save and close the VM manifest.

5. Start the VM that you edited:

   ```bash
   kubectl virt start VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you
   edited.
6. Check the `STATUS` of your VM:

   ```bash
   kubectl get gvm VM_NAME
   ```

   Make sure that your VM is in a `Running` state. If your VM requests more
   compute resources than the host can provide, your VM can't start. If the VM
   isn't in a `Running` state, check your `VirtualMachine` resource manifest and
   the compute resource availability on the host.

   The following example output shows the VM in a `Running` state:

       NAME   STATUS    AGE   IP
       vm1    Running   1m    192.168.2.72

7. View detailed information about a VM using `kubectl describe gvm`:

   ```bash
   kubectl describe gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you
   edited.

   The following example output shows the condensed information for a VM, with a
   change to the number of vCPUs successfully applied:

   ```yaml
   Name:         vm1
   Namespace:    default
   Labels:       <none>
   Annotations:  <none>
   API Version:  vm.cluster.gke.io/v1
   Kind:         VirtualMachine
   ...
   Spec:
     Compute:
       Cpu:
         Vcpus:  4
   ...
   ```

For more information, see how to
[create VMs with specific vCPU and memory compute configurations](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/compute-configurations.md.txt).

## Edit disk resources

If your storage requirements change, you can add or remove virtual disks to a
VM. To edit the disks attached to your VM, complete the following steps:

1. Stop the VM that you want to edit:

   ```bash
   kubectl virt stop VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you
   want to stop.
2. Use `kubectl` to edit the VM:

   ```bash
   kubectl edit gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you
   want to edit.
3. In your editor, update the `spec.disks` section to attach or detach disks.

   For example, the following sample `VirtualMachine` manifest shows that only a
   boot disk is attached to the VM:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: vm1
   spec:
     ...
     disks:
       - boot: true
         virtualMachineDiskName: vm1-boot-dv
     ...
   ```

   If you want to add an existing empty disk, update the disk configuration in
   your editor, as shown in the following example:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: vm1
   spec:
     ...
     disks:
       - boot: true
         virtualMachineDiskName: vm1-boot-dv
       - virtualMachineDiskName: DISK_NAME
     ...
   ```

   Replace `DISK_NAME` with the name of the disk to attach.
4. Save and close the VM manifest.

5. Start the VM that you edited:

   ```bash
   kubectl virt start VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you edited.
6. Check the `STATUS` of your VM:

   ```bash
   kubectl get gvm VM_NAME
   ```

   Make sure that your VM is in a `Running` state. If your VM requests a
   `StorageClass` or disk assignment that the host can't provide, your VM can't
   start. If the VM isn't in a `Running` state, check your `VirtualMachine` and
   `VirtualMachineDisk` resource manifests and the host storage support.
7. View detailed information about a VM using `kubectl describe gvm`:

   ```bash
   kubectl describe gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you edited.

   The following example output shows the condensed information for a VM, with
   a change to the attached disks successfully applied:

   ```yaml
   Name:         vm1
   Namespace:    default
   Labels:       <none>
   Annotations:  <none>
   API Version:  vm.cluster.gke.io/v1
   Kind:         VirtualMachine
   ...
   Spec:
     Disks:
       Name:  vm1-boot-dv
       Name:  data-disk-01
   ...
   ```

For more information, see how to
[create and manage disks](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-manage-disks.md.txt).

## Edit network resources

As your infrastructure changes, you might want to change the network
configuration for a VM. For example, you might want to connect the VM to a
different virtual network or manually assign an IP address. To edit the network
configuration for a VM, complete the following steps:

1. Stop the VM that you want to edit:

   ```bash
   kubectl virt stop VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   stop.
2. Use `kubectl` to edit the VM:

   ```bash
   kubectl edit gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   edit.
3. In your editor, update the network configuration settings that you want to
   change.

   For example, the following sample `VirtualMachine` manifest shows that the VM
   connects to a network named `backend-vlan100` and uses DHCP since no IP
   address is defined:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: vm1
   spec:
     ...
     interfaces:
       - name: eth0
         networkName: backend-vlan100
         default: true
   ...
   ```

   If you want to change the network that the VM connects to or assign a manual
   IP address, update the network configuration in your editor, as shown in the
   following example:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: vm1
   spec:
     ...
     interfaces:
       - name: eth0
         networkName: NETWORK_NAME
           ipAddresses:
             - IP_ADDRESS
         default: true
   ...
   ```

   Replace `NETWORK_NAME` with the name of the network to
   connect to, or add the `ipAddresses` section and specify the
   `IP_ADDRESS` for your VM to use.
4. Save and close the VM manifest.

5. Start the VM that you edited:

   ```bash
   kubectl virt start VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you edited.
6. Check the `STATUS` of your VM:

   ```bash
   kubectl get gvm VM_NAME
   ```

   Make sure that your VM is in a `Running` state. If your VM requests a
   network connection that the host can't provide, your VM can't start. If the VM
   isn't in a `Running` state, check your `VirtualMachine` resource manifest and
   the host network support.
7. View detailed information about a VM using `kubectl describe gvm`:

   ```bash
   kubectl describe gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you edited.

   The following example output shows the condensed information for a VM, with a
   change to the network and IP address configuration successfully applied:

   ```yaml
   Name:         vm1
   Namespace:    default
   Labels:       <none>
   Annotations:  <none>
   API Version:  vm.cluster.gke.io/v1
   Kind:         VirtualMachine
   ...
   Spec:
     Compute:
     Interfaces:
       Name:          eth0
       Network Name:  backend-vlan200
   ...
   Status:
     ...
     Interfaces:
       Dns Config:
         Nameservers:
           8.8.8.8
       gateway4:  10.200.0.9
       Ip Addresses:
         10.200.0.22/24
       Mac Address:    22:b4:e3:d2:ef:fb
       Name:           eth0
       Resource Name:  vm1-eth0-f2468
   ...
   ```

For more information, see how to
[create and manage virtual networks](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-networks.md.txt).

## What's next

- [Create VMs with specific vCPU and memory compute configurations in Google Distributed Cloud](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/compute-configurations.md.txt).
- [Create and manage disks in Google Distributed Cloud](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-manage-disks.md.txt).
- [Create and manage virtual networks in Google Distributed Cloud](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-networks.md.txt).