Kurzanleitung: VM in Google Distributed Cloud-Clustern erstellen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In dieser Kurzanleitung erfahren Sie, wie Sie mit VM Runtime on GDC eine virtuelle Maschine (VM) in der Google Distributed Cloud erstellen. VM Runtime on GDC verwendet KubeVirt, um VMs in Clustern zu orchestrieren, und ermöglicht die Arbeit mit Ihren VM-basierten Anwendungen und Arbeitslasten in einer einheitlichen Entwicklungsumgebung.
Hinweis
Wenn Sie diese Kurzanleitung abschließen möchten, benötigen Sie Zugriff auf einen Google Distributed Cloud-Cluster der Version 1.12 (anthosBareMetalVersion: 1.12) oder höher. Sie können einen beliebigen Clustertyp verwenden, der Arbeitslasten ausführen kann. Bei Bedarf können Sie Google Distributed Cloud on Compute Engine ausprobieren oder die Übersicht zur Clustererstellung aufrufen.
Aktivieren Sie die VM Runtime auf GDC
VM Runtime on GDC wird automatisch in Google Distributed Cloud-Version 1.10 oder höher installiert, ist aber standardmäßig deaktiviert. Bevor Sie VM-Ressourcen in Ihrer Google Distributed Cloud ausführen können, müssen Sie die VM-Laufzeit auf GDC aktivieren.
bmctl
In Google Distributed Cloud Version 1.11 oder höher kann das bmctl-Befehlszeilentool verwendet werden:
Verwenden Sie das Tool bmctl, um die Laufzeit zu aktivieren:
bmctlenablevmruntime--kubeconfigKUBECONFIG_PATH
Geben Sie den Pfad zur kubeconfig-Datei für Ihren Cluster an.
Google Distributed Cloud generiert die kubeconfig-Datei auf der Administrator-Workstation, wenn Sie einen Cluster erstellen. Der Pfad ist standardmäßig bmctl-workspace/CLUSTER_NAME/CLUSTER_NAME-kubeconfig.
Wenn die VM Runtime on GDC bereits aktiviert ist, gibt der Befehl einen Fehler zurück.
Benutzerdefinierte Ressource
In Google Distributed Cloud-Version 1.10 oder höher kann eine benutzerdefinierte Ressourcendefinition verwendet werden, um VM Runtime on GDC zu aktivieren. Diese benutzerdefinierte Ressource wird standardmäßig installiert.
Bearbeiten Sie die benutzerdefinierte VMRuntime-Ressource:
kubectleditvmruntime
Legen Sie enabled:true in der Spezifikation fest:
apiVersion:vm.cluster.gke.io/v1kind:VMRuntimemetadata:name:vmruntimespec:enabled:true# useEmulation defaults to "false" if not set.useEmulation:true# vmImageFormat defaults to "qcow2" if not set.vmImageFormat:qcow2
Im vorherigen Abschnitt spec können die folgenden Werte festgelegt werden:
enabled: Auf „wahr“ gesetzt, um die VM-Laufzeit auf GDC zu aktivieren
useEmulation: Wenn Ihr Knoten die Hardwarevirtualisierung nicht unterstützt oder Sie sich nicht sicher sind, legen Sie den Wert auf "true" fest. Die Hardwarevirtualisierung bietet eine bessere Leistung als die Softwareemulation. Das Feld useEmulation ist standardmäßig auf false gesetzt, wenn es nicht angegeben ist.
vmImageFormat: Unterstützt zwei Laufwerk-Image-Format-Werte: raw und qcow2. Wenn Sie vmImageFormat nicht festlegen, verwendet die VM-Laufzeit auf GDC das Laufwerk-Image-Format raw, um VMs zu erstellen. Das Format raw bietet möglicherweise eine bessere Leistung gegenüber qcow2, eine Kopie des Schreibformats, benötigt aber möglicherweise mehr Platz auf dem Laufwerk. Weitere Informationen zu den Image-Formaten für Ihre VM finden Sie in der QEMU-Dokumentation unter Dateiformate für Laufwerk-Images.
Speichern Sie die benutzerdefinierte Ressource in Ihrem Editor.
Prüfen Sie, ob die benutzerdefinierte Ressource VMRuntime aktiviert ist:
kubectldescribevmruntimevmruntime
Die Details der benutzerdefinierten Ressource VMRuntime enthalten den Abschnitt Status.
Die VM Runtime on GDC ist aktiviert und funktioniert, wenn für VMRuntime.Status.Ready der Wert true angezeigt wird.
virtctl-Clienttool installieren
Erstellen und verwalten Sie VMs, indem Sie das virtctl-Clienttool installieren.
Installieren Sie das virtctl-CLienttool als kubectl-Plug-in.
Mit den Anmeldedaten können Sie das virtctl-Clienttool authentifizieren und herunterladen und dann unter /usr/bin/kubectl-virt auf Ihrem lokalen Computer installieren.
Überprüfen Sie, ob das Plug-in virtctl installiert ist:
kubectlpluginlist
Wenn kubectl-virt in der Antwort aufgeführt ist, wurde das Plug-in erfolgreich installiert.
Wenn kubectl-virt nicht aufgeführt ist, prüfen Sie die Datei install-virtctl.log, wie sie in der Ausgabe des vorherigen bmctl install-Befehls angegeben, z. B. bmctl-workspace/log/install-virtctl-[date]/install-virtctl.log.
VM erstellen
In dieser Kurzanleitung erstellen Sie mit der kubectl-Befehlszeile eine VM, die ein öffentliches VM-Image und Standardanmeldedaten verwendet.
Erstellen Sie eine VM in Ihrem Cluster. Das Plug-in virtctl wird mit dem Befehl kubectl verwendet:
Dieser Befehl erstellt eine Ubuntu 20.04-VM und Standardeinstellungen von 2 CPU, 4Gi Arbeitsspeicher und ein 20Gi Bootlaufwerk im ReadWriteOnce-Modus und unter Verwendung der Speicherklasse local-shared. Ersetzen Sie die folgenden Werte:
VM_NAME: der Name Ihrer VM. VM-Namen dürfen nur Kleinbuchstaben, Ziffern oder „-“ enthalten, mit einem alphanumerischen Zeichen beginnen und enden und maximal 63 Zeichen lang sein. Weitere Informationen finden Sie in der Kubernetes-Dokumentation unter RFC 1123-Labelnamen.
USERNAME: Nutzername für das Konto, das auf der VM erstellt werden soll.
PASSWORD: das Passwort für das Nutzerkonto.
Wenn ein Fehler zu Befehlszeilenparametern zurückgegeben wird, prüfen Sie, ob Ihr Cluster die Version 1.11.1 oder höher hat und ob Sie die neueste Version des Clienttools virtctl haben. Weitere Informationen zu CLI-Fehlern finden Sie im Konsolenprotokoll. Informationen zu Nutzernamen- und Passwortregeln finden Sie in der Dokumentation des Gastbetriebssystems. Wenn etwas nicht wie erwartet funktioniert, sehen Sie unter Bekannte Probleme mit der VM-Laufzeit in GDC nach.
Es kann einige Minuten dauern, bis die VM erstellt ist. Prüfen Sie den Status der VM mit dem Befehl kubectl:
kubectlgetgvm
Das folgende Ausgabebeispiel zeigt die VM im Status Running:
NAME STATUS AGE IP
vm-sample1 Running 64s 192.168.2.124
Mit VM verbinden.
Wenn Ihre VM ausgeführt wird, stellen Sie eine Verbindung zur Konsole der VM her.
Verwenden Sie kubectl, um über die Konsole auf eine VM zuzugreifen:
kubectlvirtconsoleVM_NAME
Geben Sie bei entsprechender Aufforderung die Nutzeranmeldedaten ein, die Sie zum Erstellen der VM verwendet haben.
Nachdem Sie erfolgreich eine Verbindung zur Konsole der VM hergestellt haben, beenden Sie die VM-Sitzung und die Konsole:
Ctrl+]
Bereinigen
So bereinigen Sie die in dieser Kurzanleitung erstellten Ressourcen:
Verwenden Sie kubectl zum Löschen der VM und des zugehörigen DataVolumes:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[],[],null,["This quickstart shows you how to use VM Runtime on GDC to create a\nvirtual machine (VM) on Google Distributed Cloud. VM Runtime on GDC uses\n[KubeVirt](https://kubevirt.io/)\nto orchestrate VMs on clusters, and lets you work with your VM-based apps and\nworkloads in a uniform development environment.\n\nBefore you begin\n\nTo complete this quickstart, you need access to Google Distributed Cloud version\n1.12 (`anthosBareMetalVersion: 1.12`) or higher cluster. You can use any\ncluster type capable of running workloads. If needed,\n[try Google Distributed Cloud on Compute Engine](/kubernetes-engine/distributed-cloud/bare-metal/docs/try/gce-vms)\nor see the\n[cluster creation overview](/kubernetes-engine/distributed-cloud/bare-metal/docs/installing/creating-clusters/create-clusters-overview).\n\nEnable VM Runtime on GDC\n\nVM Runtime on GDC is automatically installed in Google Distributed Cloud\nversion 1.10 or higher, but is disabled by default. Before you can run VM\nresources in your Google Distributed Cloud, you must enable the\nVM Runtime on GDC. \n\nbmctl\n\nGoogle Distributed Cloud version 1.11 or higher can use the `bmctl` command-line tool:\n\n- To enable the runtime, use the `bmctl` tool:\n\n bmctl enable vmruntime --kubeconfig \u003cvar label=\"Kubeconfig path\" translate=\"no\"\u003eKUBECONFIG_PATH\u003c/var\u003e\n\n Provide the path to the kubeconfig file for your cluster.\n Google Distributed Cloud generates the kubeconfig file on the admin\n workstation when you create a cluster. By default, the path is\n `bmctl-workspace/`\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e`-kubeconfig`.\n\n If VM Runtime on GDC is already enabled, the command returns an\n error.\n\nCustom resource\n\nGoogle Distributed Cloud version 1.10 or higher can use a custom resource definition\nto enable VM Runtime on GDC. This custom resource is installed by\ndefault.\n\n1. Edit the `VMRuntime` custom resource:\n\n kubectl edit vmruntime\n\n2. Set `enabled:true` in the spec:\n\n apiVersion: vm.cluster.gke.io/v1\n kind: VMRuntime\n metadata:\n name: vmruntime\n spec:\n enabled: true\n # useEmulation defaults to \"false\" if not set.\n useEmulation: true\n # vmImageFormat defaults to \"qcow2\" if not set.\n vmImageFormat: qcow2\n\n In the preceding `spec` section, the following values can be set:\n - `enabled`: set to true to enable VM Runtime on GDC\n - `useEmulation`: If your node doesn't support hardware virtualization, or you aren't sure, set the value to true. If available, hardware virtualization provides better performance than software emulation. The `useEmulation` field defaults to `false`, if it isn't specified.\n - `vmImageFormat`: Supports two disk image format values: `raw` and `qcow2`. If you don't set `vmImageFormat`, the VM Runtime on GDC uses the `raw` disk image format to create VMs. The `raw` format may provide improved performance over `qcow2`, a copy on write format, but may use more disk. For more information about the image formats for your VM, see [Disk image file formats](https://www.qemu.org/docs/master/system/images.html#disk-image-file-formats) in the QEMU documentation.\n3. Save the custom resource in your editor.\n\n4. Verify that the `VMRuntime` custom resource is enabled:\n\n kubectl describe vmruntime vmruntime\n\n The details of the `VMRuntime` custom resource include a `Status` section.\n VM Runtime on GDC is enabled and working when\n `VMRuntime.Status.Ready` shows as `true`.\n\nInstall the `virtctl` client tool\n\nTo create and manage VMs, install the\n[virtctl client tool](https://kubevirt.io/user-guide/operations/virtctl_client_tool/).\n\n1. Install the `virtctl` client tool as a `kubectl` plugin:\n\n export GOOGLE_APPLICATION_CREDENTIALS=\"\u003cvar label=\"name\" translate=\"no\"\u003ePATH_TO_SERVICE_ACCOUNT_KEY\u003c/var\u003e/bm-gcr.json\"\n sudo -E bmctl install virtctl\n\n The credentials let you authenticate and download the `virtctl` client tool,\n then install to `/usr/bin/kubectl-virt` on your local machine.\n2. Verify that the `virtctl` plugin is installed:\n\n kubectl plugin list\n\n If `kubectl-virt` is listed in the response, the plugin is successfully\n installed.\n\n If `kubectl-virt` is not listed, check the `install-virtctl.log` file as noted\n in the output of the previous `bmctl install` command, such as\n `bmctl-workspace/log/install-virtctl-[date]/install-virtctl.log`.\n\nCreate a VM\n\nIn this quickstart, you use the `kubectl` CLI to create a VM that uses a public\nVM image and default credentials.\n| **Note:** For instructions on creating a VM from a `VirtualMachine` YAML manifest file, see [Tutorial: Create and manage a Linux VM in VM Runtime on GDC](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/tutorial-create-vm).\n\n1. Create a VM in your cluster. The `virtctl` plugin is used with the\n `kubectl` command:\n\n kubectl virt create vm \u003cvar label=\"name\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n --image ubuntu20.04 \\\n --configure-initial-password \u003cvar label=\"username\" translate=\"no\"\u003eUSERNAME\u003c/var\u003e:\u003cvar label=\"name\" translate=\"no\"\u003ePASSWORD\u003c/var\u003e\n\n This command creates an *Ubuntu 20.04* VM and defaults of *2* CPU, *4Gi*\n memory, and a *20Gi* boot disk in *ReadWriteOnce* mode using the\n *local-shared* storage class. Replace the following values:\n - \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e: name for your VM. VM names must contain only lowercase alphanumeric characters or '-', start and end with an alphanumeric character, and contain at most 63 characters. For more information, see [RFC 1123 Label Names](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names) in the Kubernetes documentation.\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: user name for the account to create on the VM.\n - \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e: password for the user account.\n\n If you receive an error about CLI parameters, verify that your cluster is at\n version `1.11.1` or higher and that you have the latest version of the\n `virtctl` client tool. For more information about CLI errors, consult the\n console log. For username and password rules, see the documentation for the\n guest operating system (OS). If something isn't working as expected, check for\n [VM Runtime on GDC known issues](/kubernetes-engine/distributed-cloud/bare-metal/docs/troubleshooting/known-issues).\n | **Note:** The preceding command creates a YAML file, such as `vm-sample1.yaml`, in the `~/google-virtctl` directory. You can view the content of this file to see the definition of the Kubernetes resources that were created by VM Runtime on GDC.\n2. It can take a few minutes to create the VM. Check the status of the VM with\n the `kubectl` command:\n\n kubectl get gvm\n\n The following example output shows the VM in a `Running` state: \n\n NAME STATUS AGE IP\n vm-sample1 Running 64s 192.168.2.124\n\nConnect to your VM\n\nWhen your VM is running, connect to the console of the VM.\n\n1. To access a VM from the console, use `kubectl`:\n\n kubectl virt console \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e\n\n2. When prompted, enter the user credentials you specified to create the VM.\n\n3. After you have successfully connected to the console of the VM, exit the VM\n session and console:\n\n Ctrl + ]\n\nClean up\n\nTo clean up the resources created in this quickstart, follow these steps.\n\n1. To delete the VM and associated DataVolume, use `kubectl`:\n\n kubectl virt delete vm \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e --all\n\nWhat's next\n\n- [Manage the power state of a VM in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/manage-power-state).\n- [Edit a VM in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/edit-vm).\n- [View VM console logs in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/view-console-logs)."]]