When you create VMs that use VM Runtime on Google Distributed Cloud, you can configure compute resources in two ways:
- Manually specify CPU and memory: Define compute resources
directly in the
VirtualMachinemanifest. This approach is useful for one-time VMs or custom workloads that require unique resource allocations. - Create and use VM types: Define reusable
VirtualMachineTypecustom resources that standardize CPU and memory allocations. This approach is useful for managing fleets of VMs, ensuring compute consistency across your cluster, and simplifying VM provisioning for developers.
Before you begin
To manually specify CPU and memory resources and to create and use VM types, you need access to the following resources:
- A Distributed Cloud connected cluster, version 1.9.0 or higher.
- The Kubernetes command-line tool,
kubectl, installed and configured to access your cluster. For more information, see installkubectl. - Optional: The
virtctlclient tool installed as a plugin forkubectl. If needed, see Install thevirtctlmanagement tool.
Create a VM and specify the CPU and memory
When you create a VM, you can manually specify the CPU and memory requirements. Use this feature to create VMs that have the appropriate compute resources to match your application needs.
To create a VM and specify the CPU and memory, use a VirtualMachine manifest.
In the editor of your choice, create a
VirtualMachinemanifest, such asmy-custom-vm.yaml:apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME namespace: NAMESPACE spec: compute: cpu: vcpus: VCPU_NUMBER memory: capacity: MEMORY_SIZE interfaces: - name: eth0 networkName: L2_NETWORK_NAME default: true disks: - virtualMachineDiskName: VM_BOOT_NAME-boot-dv boot: true
In this YAML file, define the following settings:
VM_NAME: the name for your VM.NAMESPACE: the target namespace for your VM.L2_NETWORK_NAME: The name of the L2 network to connect the VM to.VCPU_NUMBER: The number of vCPUs to assign to the VM. You can assign between 1 and 96 vCPUs to a VM.MEMORY_SIZE: The amount of memory to assign to the VM. You can assign between 1 Mi and 1 Ti of memory to a VM. For more information, see Memory resource units in the Kubernetes documentation.VM_BOOT_NAME: the name of your VM boot disk. The boot disk must already exist. For more information, see Create a virtual machine disk from a virtual machine image.
The VM connects the
eth0interface to the specified L2 network.To create the VM, apply the manifest to your Distributed Cloud connected cluster using the
kubectl applycommand:kubectl apply -f my-custom-vm.yamlTo verify that the VM is created, use the
kubectl getcommand:kubectl get vm VM_NAME -n NAMESPACEThe expected output shows the VM status. You can also use the
kubectl describecommand to view the detailed configuration, including the assigned CPU and memory.
Create and use VM types
When you enable VM Runtime on GDC, the VirtualMachineType custom
resource definition becomes available in your cluster. You can use this resource
type to create reusable templates that define specific CPU and memory allocations.
By creating custom VM types for your different workloads, you can provision
multiple VMs with consistent compute resource configurations.
If VM Runtime on GDC is enabled
in Distributed Cloud connected, a predefined VM type might be
available. You can't update this predefined VM type. The following definition
shows the default example-machinetype VM type:
apiVersion: vm.cluster.gke.io/v1
kind: VirtualMachineType
metadata:
name: "example-machinetype"
labels:
vm.cluster.gke.io/predefined-machinetype: "true"
spec:
cpu:
vcpus: 2
memory:
capacity: 4G
Create a VM type
You can create your own VM types to fit the compute needs of your workloads.
In the editor of your choice, create a
VirtualMachineTypemanifest, such asmy-vm-type.yaml:apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachineType metadata: name: VM_TYPE_NAME spec: cpu: vcpus: VCPU_NUMBER memory: capacity: MEMORY_SIZE
In this VM type, define the following settings:
VM_TYPE_NAME: the name for your VM type.VCPU_NUMBER: the number of vCPUs to assign to the VM. You can assign between 1 and 96 vCPUs to a VM.MEMORY_SIZE: the amount of memory to assign to the VM. You can assign between 1 Mi and 1 Ti of memory to a VM. For more information, see Memory resource units in the Kubernetes documentation.
To create the VM type, apply the manifest to your Distributed Cloud connected cluster using the
kubectl applycommand:kubectl apply -f my-vm-type.yamlTo verify that the VM type is created, run the
kubectl getcommand:kubectl get virtualmachinetype VM_TYPE_NAME
Create a VM using a VM type
To apply the CPU and memory settings defined in a VM type to your VM, specify the
name of the VM type in the compute section of the VirtualMachine manifest.
In the editor of your choice, create a
VirtualMachinemanifest, such asmy-custom-vm.yaml. In this YAML file, specify the name of the custom VM type that you created in the previous section, such asmy-vm-type, as the value for thevirtualMachineTypeName.apiVersion: vm.cluster.gke.io/v1 kind: VirtualMachine metadata: name: VM_NAME namespace: NAMESPACE spec: compute: virtualMachineTypeName: VM_TYPE_NAME interfaces: - name: eth0 networkName: L2_NETWORK_NAME default: true disks: - virtualMachineDiskName: VM_BOOT_NAME-boot-dv boot: true
Define the following settings:
VM_NAME: the name for your VM.NAMESPACE: the target namespace for your VM.L2_NETWORK_NAME: The name of the L2 network to connect the VM to.VM_TYPE_NAME: the name of the custom VM type that you created in the previous section, such asmy-vm-type.VM_BOOT_NAME: the name of your VM boot disk. The boot disk must already exist. For more information, see Create a virtual machine disk from a virtual machine image.
The VM connects the
eth0interface to the specified L2 network.To create the VM, apply the manifest to your Distributed Cloud connected cluster using the
kubectl applycommand:kubectl apply -f my-custom-vm.yamlTo verify that the VM is using the VM type, run the
kubectl getcommand with the-o jsonpathoption:kubectl get vm VM_NAME -n NAMESPACE -o jsonpath='{.spec.compute.virtualMachineTypeName}'The expected output displays the name of your VM type.