This document is intended for application owners that run Google Distributed Cloud. This document shows you how to create and manage disk resources for virtual machines (VMs) that use VM Runtime on Google Distributed Cloud.
Before you begin
To complete this document, you need access to the following resources:
- Access to Google Distributed Cloud version 1.12.0 (
anthosBareMetalVersion: 1.12.0
) or higher cluster. You can use any cluster type capable of running workloads. If needed, try Google Distributed Cloud on Compute Engine or see the cluster creation overview. - The
virtctl
client tool installed as a plugin forkubectl
. If needed, install the virtctl client tool.
Create a VM with an attached disk
When you create a VM, you can attach an existing boot or data disk, create a disk from an image (including for the boot disk), or create a blank disk.
Blank disk
In this scenario, you create a blank disk and attach it to the VM. This scenario lets you create a data disk to store application data.
Create a manifest that defines a
VirtualMachineDisk
andVirtualMachine
, such as my-vm.yaml, in the editor of your choice:nano my-vm.yaml
Copy and paste the following YAML definition:
apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineDisk metadata: name: DISK_NAME spec: size: 10Gi --- apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME spec: interfaces: - name: eth0 networkName: pod-network default: true disks: - boot: true virtualMachineDiskName: VM_NAME-boot-dv - virtualMachineDiskName: DISK_NAME
This example creates a blank
10Gi
(10 gibibyte) disk namedDISK_NAME
. In the VM'sspec.disks
section, you must also attach a boot disk, such as from an image as shown in the next section.Save and close the manifest file in your editor.
Create the VM and disk using
kubectl
:kubectl apply -f my-vm.yaml
From image
In this scenario, you create a disk from an image and attach it to the VM. This scenario lets you create a boot disk, for example, from an image. You can also create and attach data disks from an image.
Create a manifest that defines a
VirtualMachineDisk
andVirtualMachine
, such as my-vm.yaml, in the editor of your choice:nano my-vm.yaml
Copy and paste the following YAML definition:
apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineDisk metadata: name: VM_NAME-boot-dv spec: size: 20Gi source: http: url: https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img --- apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME spec: interfaces: - name: eth0 networkName: pod-network default: true disks: - boot: true virtualMachineDiskName: VM_NAME-boot-dv
This example creates a
20Gi
(20 gibibyte) disk namedVM_NAME-boot-dv
using a public Ubuntu image. In the VM'sspec.disks
section, the disk is set toboot: true
.Save and close the manifest in your editor.
Create the VM and disk using
kubectl
:kubectl apply -f my-vm.yaml
Existing disk
In this scenario, you create a blank disk and attach it to the VM. This scenario lets you create a data disk to store application data.
Create a
VirtualMachine
manifest, such as my-vm.yaml, in the editor of your choice:nano my-vm.yaml
Copy and paste the following YAML definition:
apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME spec: interfaces: - name: eth0 networkName: pod-network default: true disks: - boot: true virtualMachineDiskName: VM_NAME-boot-dv - virtualMachineDiskName: EXISTING_DISK_NAME
This example attaches an existing disk named
EXISTING_DISK_NAME
.In the VM's
spec.disks
section, you must also attach a boot disk, such as from an image as shown in the preceding section.Save and close the VM manifest in your editor.
Create the VM using
kubectl
:kubectl apply -f my-vm.yaml
Create and attach disks to existing VM
If you have an existing VM, you can create and attach disks to support your application lifecycles. The VM must be in a stopped state before you attach a disk.
Blank disk
In this scenario, you create a blank disk and attach it to the VM. This scenario lets you create a data disk to store application data.
Use
kubectl
to stop the VM, if needed:kubectl virt stop vm VM_NAME
Replace
VM_NAME
with the name of the VM that you want to stop.Edit your existing VM resource, such as
my-vm
:kubectl edit gvm VM_NAME
Update the
VirtualMachine
YAML manifest to add aVirtualMachineDisk
section at the top, and then attach the disk at the end of the VM'sspec.disks
section:apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineDisk metadata: name: DISK_NAME spec: size: 10Gi --- apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME spec: interfaces: - name: eth0 networkName: pod-network default: true disks: - boot: true virtualMachineDiskName: VM_NAME-boot-dv - virtualMachineDiskName: DISK_NAME
This example creates a blank
10Gi
(10 gibibyte) disk namedDISK_NAME
.Save and close the updated VM manifest in your editor.
Use
kubectl
to start the VM:kubectl virt start vm VM_NAME
Replace
VM_NAME
with the name of the VM that you want to start.
From image
In this scenario, you create a disk from a source image and attach it to the VM.
Use
kubectl
to stop the VM, if needed:kubectl virt stop vm VM_NAME
Replace
VM_NAME
with the name of the VM that you want to stop.Edit your existing VM resource, such as
my-vm
:kubectl edit gvm VM_NAME
Update the
VirtualMachine
manifest to add aVirtualMachineDisk
section at the top, and then attach the disk at the end of the VM'sspec.disks
section:apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineDisk metadata: name: DISK_NAME spec: size: 10Gi source: http: url: http://example.com/my-disk-img.qcow2 --- apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME spec: interfaces: - name: eth0 networkName: pod-network default: true disks: - boot: true virtualMachineDiskName: VM_NAME-boot-dv - virtualMachineDiskName: DISK_NAME
This example creates a
10Gi
(10 gibibyte) disk namedDISK_NAME
from thehttp://example.com/my-disk-img.qcow2
HTTP source.Save and close the updated VM manifest in your editor.
Use
kubectl
to start the VM:kubectl virt start vm VM_NAME
Replace
VM_NAME
with the name of the VM that you want to start.
Create a disk
In this scenario, you create the disk resources separately from the VM resources. This scenario lets you create disks ahead of time, and then attach to VMs as needed.
Blank disk
To create a blank disk, complete the following steps.
Create a
VirtualMachineDisk
manifest, such as my-disk.yaml, in the editor of your choice:nano my-disk.yaml
Copy and paste the following YAML definition:
apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineDisk metadata: name: DISK_NAME spec: size: 10Gi
This example creates a blank
10Gi
(10 gibibyte) disk namedDISK_NAME
.Save and close the disk manifest in your editor.
Create the disk using
kubectl
:kubectl apply -f my-disk.yaml
From image
To create a disk from an image, complete the following steps.
Create a
VirtualMachineDisk
manifest, such as my-disk.yaml, in the editor of your choice:nano my-disk.yaml
Copy and paste the following YAML definition:
apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineDisk metadata: name: DISK_NAME spec: size: 20Gi source: http: url: https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img
This example creates a
20Gi
(20 gibibyte) disk namedDISK_NAME
using a public Ubuntu image.Save and close the disk manifest in your editor.
Create the disk using
kubectl
:kubectl apply -f my-disk.yaml
What's next
- Create and use credentials to import images from Cloud Storage.
- Create and use storage classes in Google Distributed Cloud.
- When you no longer need VMs or their virtual disk resources, Delete a VM in Google Distributed Cloud.