Criar uma VM com recursos específicos de CPU e memória usando o ambiente de execução de VM no GDC
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Este documento é destinado a proprietários de aplicativos e administradores de plataforma
que executam o Google Distributed Cloud. Neste documento, mostramos como criar e usar tipos de
VM ou especificar manualmente os recursos de CPU e memória ao criar VMs que usam
o ambiente de execução da VM no GDC.
Antes de começar
Para concluir este documento, você precisa de acesso aos seguintes recursos:
Ao criar uma VM, é possível especificar manualmente os requisitos de CPU e memória.
Esse recurso permite criar VMs com os recursos de computação apropriados para atender
às necessidades do seu aplicativo.
Para criar uma VM e especificar manualmente os requisitos de CPU e memória, siga as etapas abaixo.
O disco de inicialização chamado VM_NAME-boot-dv já precisa
existir. Para mais informações, consulte Criar e gerenciar discos virtuais.
Salve e feche o manifesto da VM no editor.
Crie a VM usando kubectl:
kubectlapply-fmy-custom-vm.yaml
Criar e usar tipos de VM
Quando você ativa o ambiente de execução de VM no GDC, uma nova definição de recurso personalizado do VirtualMachineType fica disponível. Essa definição é usada para especificar os recursos de CPU e memória de uma VM. É possível criar tipos de VM para as diferentes cargas de trabalho
e aplicar um conjunto consistente de recursos de computação às VMs com base nesses
tipos.
Se o ambiente de execução de VMs no GDC estiver ativado no Google Distributed Cloud, o
vm-controller-manager vai instalar um tipo de VM predefinido. A definição a seguir
mostra o tipo de VM padrão example-machinetype:
Não é possível atualizar este tipo de VM predefinido. Esse tipo de VM predefinido será
reinstalado se não existir no cluster sempre que o
vm-controller-manager for iniciado ou reiniciado, como se você tiver excluído o tipo
de VM.
Criar um tipo de VM
É possível criar seus próprios tipos de VM para atender às necessidades de computação das cargas de trabalho.
Crie um manifesto de VirtualMachineType, como my-vm-type.yaml, no editor de sua escolha:
Nesse arquivo YAML, especifique o nome do tipo de VM personalizado que você criou na
seção anterior, como my-vm-type, como o valor de
virtualMachineTypeName.
A VM conecta eth0 à rede pod-network padrão.
O disco de inicialização chamado VM_NAME-boot-dv já precisa
existir. Para mais informações, consulte Criar e gerenciar discos virtuais.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)."]]