Crea una VM con recursos de CPU y memoria específicos mediante el entorno de ejecución de VM en GDC
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Este documento está dirigido a los propietarios de aplicaciones y administradores de plataformas que ejecutan Google Distributed Cloud. En este documento, se muestra cómo crear y usar tipos de VM o especificar de forma manual recursos de CPU y memoria cuando creas VMs que usan el entorno de ejecución de VMs en GDC.
Antes de comenzar
Para completar este documento, necesitas acceso a los siguientes recursos:
Cuando creas una VM, puedes especificar manualmente los requisitos de CPU y memoria.
Esta capacidad te permite crear VM con los recursos de procesamiento adecuados para satisfacer las necesidades de tu aplicación.
Para crear una VM y especificar manualmente los requisitos de CPU y memoria, sigue estos pasos.
La VM conecta eth0 a la red pod-network predeterminada.
El disco de arranque llamado VM_NAME-boot-dv ya debe existir. Si deseas obtener más información, consulta Crea y administra discos virtuales.
Guarda y cierra el manifiesto de la VM en el editor.
Crea la VM mediante kubectl:
kubectlapply-fmy-custom-vm.yaml
Crea y usa tipos de VM
Cuando habilitas el entorno de ejecución de VM en GDC, se encuentra disponible una definición de recurso personalizado nuevo de VirtualMachineType. Esta definición se usa para especificar los recursos de CPU y memoria de una VM. Puedes crear tipos de VM para las diferentes cargas de trabajo que necesites y aplicar un conjunto coherente de recursos de procesamiento a las VM según estos tipos.
Si el entorno de ejecución de VM en GDC está habilitado en Google Distributed Cloud, vm-controller-manager instala un tipo de VM predefinido. En la siguiente definición, se muestra el tipo de VM example-machinetype predeterminado:
No puedes actualizar este tipo de VM predefinido. Este tipo de VM predefinido se vuelve a instalar si no existe en el clúster cada vez que se inicia o se reinicia vm-controller-manager, por ejemplo, si borraste el tipo de VM.
Crea un tipo de VM
Puedes crear tus propios tipos de VM para que se adapten a las necesidades de procesamiento de tus cargas de trabajo.
Crea un manifiesto VirtualMachineType como my-vm-type.yaml, en el editor que elijas:
En este archivo YAML, especifica el nombre de tu tipo de VM personalizado que creaste en la sección anterior, como my-vm-type, como el valor para virtualMachineTypeName.
La VM conecta eth0 a la red pod-network predeterminada.
El disco de arranque llamado VM_NAME-boot-dv ya debe existir. Si deseas obtener más información, consulta Crea y administra discos virtuales.
Guarda y cierra el manifiesto de la VM en el editor.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-01 (UTC)"],[],[],null,["This document is intended for application owners and platform administrators\nthat run Google Distributed Cloud. This document shows you how to create and use VM\ntypes or manually specify CPU and memory resources when you create VMs that use\nVM Runtime on GDC.\n\nBefore you begin\n\nTo complete this document, you need access to the following resources:\n\n- 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](/kubernetes-engine/distributed-cloud/bare-metal/docs/try/gce-vms) or see the [cluster creation overview](/kubernetes-engine/distributed-cloud/bare-metal/docs/installing/creating-clusters/create-clusters-overview).\n- The `virtctl` client tool installed as a plugin for `kubectl`. If needed, [install the virtctl client tool](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/quickstart#install_the_virtctl_client_tool).\n\nCreate a VM\n\nWhen you create a VM, you can manually specify the CPU and memory requirements.\nThis ability lets you create VMs with the appropriate compute resources to match\nyour application needs.\n\nTo create a VM and manually specify the CPU and memory requirements, use the\nfollowing steps. \n\nCLI\n\n- Use `kubectl` to create a VM:\n\n kubectl virt create vm \u003cvar label=\"vm_name\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n --image ubuntu20.04 \\\n --cpu \u003cvar label=\"vcpu_number\" translate=\"no\"\u003eCPU_NUMBER\u003c/var\u003e \\\n --memory \u003cvar label=\"memory_size\" translate=\"no\"\u003eMEMORY_SIZE\u003c/var\u003e\n\n Replace the following values:\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name for your VM. For more information on name constraints, see [Object names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/).\n - \u003cvar translate=\"no\"\u003eCPU_NUMBER\u003c/var\u003e: The number of virtual CPUs (vCPUs)to assign to the VM.\n - You can assign between 1 and 96 vCPUs to a VM.\n - \u003cvar translate=\"no\"\u003eMEMORY_SIZE\u003c/var\u003e: The amount of memory to assign to the VM.\n - You can assign between 1M and 1T of memory to a VM. For more information, see [Memory resource units](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory).\n\n | **Note:** In the `~/google-virtctl` directory, a \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e`.yaml` file is created. You can view the content of this file to see the definition of the Kubernetes resources that were created by the VM Runtime on GDC.\n\nManifest\n\n1. Create a `VirtualMachine` manifest, such as *my-custom-vm.yaml*, in the\n editor of your choice:\n\n nano my-custom-vm.yaml\n\n2. Copy and paste the following YAML manifest:\n\n apiVersion: vm.cluster.gke.io/v1\n kind: VirtualMachine\n metadata:\n name: \u003cvar label=\"vm_name\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVM_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n compute:\n cpu:\n vcpus: \u003cvar label=\"vcpu_number\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVCPU_NUMBER\u003c/span\u003e\u003c/var\u003e\n memory:\n capacity: \u003cvar label=\"memory_size\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eMEMORY_SIZE\u003c/span\u003e\u003c/var\u003e\n interfaces:\n - name: eth0\n networkName: pod-network\n default: true\n disks:\n - virtualMachineDiskName: \u003cvar label=\"vm_name\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVM_NAME\u003c/span\u003e\u003c/var\u003e-boot-dv\n boot: true\n\n In this YAML file, define the following settings:\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name for your VM. For more information on name constraints, see [Object names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/).\n - \u003cvar translate=\"no\"\u003eVCPU_NUMBER\u003c/var\u003e: The number of vCPUs to assign to the VM.\n - You can assign between 1 and 96 vCPUs to a VM.\n - \u003cvar translate=\"no\"\u003eMEMORY_SIZE\u003c/var\u003e: The amount of memory to assign to the VM.\n - You can assign between 1M and 1T of memory to a VM. For more information, see [Memory resource units](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory).\n\n The VM connects `eth0` to the default `pod-network` network.\n\n The boot disk named \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e`-boot-dv` must already\n exist. For more information, see\n [Create and manage virtual disks](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/create-manage-disks).\n3. Save and close the VM manifest in your editor.\n\n4. Create the VM using `kubectl`:\n\n kubectl apply -f my-custom-vm.yaml\n\nCreate and use VM types\n\nWhen you enable VM Runtime on GDC, a new *VirtualMachineType* custom\nresource definition is available. This definition is used to specify CPU and\nmemory resources of a VM. You can create VM types for the different workloads\nyou need, and apply a consistent set of compute resources to VMs based on these\ntypes.\n\nIf VM Runtime on GDC is enabled in Google Distributed Cloud, the\n`vm-controller-manager` installs a predefined VM type. The following definition\nshows the default `example-machinetype` VM type: \n\n apiVersion: vm.cluster.gke.io/v1\n kind: VirtualMachineType\n metadata:\n name: \"example-machinetype\"\n labels:\n vm.cluster.gke.io/predefined-machinetype: \"true\"\n spec:\n cpu:\n vcpus: 2\n memory:\n capacity: 4G\n\nYou can't update this predefined VM type. This predefined VM type is\nre-installed if it doesn't exist in the cluster every time the\n`vm-controller-manager` is started or restarted, such as if you deleted the VM\ntype.\n\nCreate a VM type\n\nYou can create your own VM types to fit the compute needs of your workloads.\n\n1. Create a `VirtualMachineType` manifest such as *my-vm-type.yaml*, in the\n editor of your choice:\n\n nano my-vm-type.yaml\n\n2. Copy and paste the following YAML manifest:\n\n apiVersion: vm.cluster.gke.io/v1\n kind: VirtualMachineType\n metadata:\n name: \u003cvar label=\"VM type name\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003emy-vm-type\u003c/span\u003e\u003c/var\u003e\n spec:\n cpu:\n vcpus: \u003cvar label=\"vcpu_number\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVCPU_NUMBER\u003c/span\u003e\u003c/var\u003e\n memory:\n capacity: \u003cvar label=\"memory_size\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eMEMORY_SIZE\u003c/span\u003e\u003c/var\u003e\n\n In this VM type, you define the following settings:\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name for your VM. For more information on name constraints, see [Object names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/).\n - \u003cvar translate=\"no\"\u003eVCPU_NUMBER\u003c/var\u003e: The number of vCPUs to assign to the VM.\n - You can assign between 1 and 96 vCPUs to a VM.\n - \u003cvar translate=\"no\"\u003eMEMORY_SIZE\u003c/var\u003e: The amount of memory to assign to the VM.\n - You can assign between 1M and 1T of memory to a VM. For more information, see [Memory resource units](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory).\n3. Save and close the VM type manifest in your editor.\n\n4. Create the VM type using `kubectl`:\n\n kubectl apply -f my-vm-type.yaml\n\nCreate a VM using a VM type\n\nSpecify a VM type in your `VirtualMachine` manifest to apply predefined\n`compute` settings to your VM.\n\n1. Create a `VirtualMachine` manifest, such as *my-custom-vm.yaml*, in the\n editor of your choice.\n\n nano my-custom-vm.yaml\n\n2. Copy and paste the following YAML manifest:\n\n apiVersion: vm.cluster.gke.io/v1\n kind: VirtualMachine\n metadata:\n name: \u003cvar label=\"vm_name\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVM_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n compute:\n virtualMachineTypeName: \u003cvar label=\"vm_type_name\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003emy-vm-type\u003c/span\u003e\u003c/var\u003e\n interfaces:\n - name: eth0\n networkName: pod-network\n default: true\n disks:\n - virtualMachineDiskName: \u003cvar label=\"vm_name\" translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eVM_NAME\u003c/span\u003e\u003c/var\u003e-boot-dv\n boot: true\n\n In this YAML file, specify the name of your custom VM type that you created in\n the previous section, such as \u003cvar translate=\"no\"\u003emy-vm-type\u003c/var\u003e, as the value for\n the `virtualMachineTypeName`.\n\n The VM connects `eth0` to the default `pod-network` network.\n\n The boot disk named \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e`-boot-dv` must already\n exist. For more information, see\n [Create and manage virtual disks](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/create-manage-disks).\n3. Save and close the VM manifest in your editor.\n\n4. Create the VM using `kubectl`:\n\n kubectl apply -f my-custom-vm.yaml\n\nWhat's next\n\n- [Edit a VM in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/edit-vm).\n- When you no longer need VMs, [Delete a VM in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/delete)."]]