Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez arrêter, démarrer et redémarrer des VM pour prendre en charge le cycle de vie de vos applications. Par exemple, vous pouvez modifier le nombre de processeurs virtuels (vCPU) attribués ou la quantité de mémoire allouée à une VM. Vous devez arrêter la VM avant de modifier la configuration. Une fois que vous avez terminé, vous devez arrêter l'état d'alimentation pour appliquer les modifications. Cette page explique comment arrêter, démarrer et redémarrer vos VM lors de ces processus.
Avant de commencer
Pour utiliser les commandes de l'interface de ligne de commande (CLI) gdcloud, assurez-vous d'avoir téléchargé, installé et configuré la CLI gdcloud.
Toutes les commandes pour Distributed Cloud utilisent la CLI gdcloud ou kubectl et nécessitent un environnement de système d'exploitation (OS).
Obtenir le chemin d'accès au fichier kubeconfig
Pour exécuter des commandes sur le serveur de l'API Management, assurez-vous de disposer des ressources suivantes :
Connectez-vous et générez le fichier kubeconfig pour le serveur d'API Management si vous n'en avez pas.
Utilisez le chemin d'accès au fichier kubeconfig du serveur de l'API Management pour remplacer MANAGEMENT_API_SERVER dans ces instructions.
Si vous souhaitez réduire au minimum le temps de démarrage de votre VM, suivez les instructions de la section Réduire le temps de démarrage de la VM avant de démarrer votre VM.
Demander des autorisations et un accès
Pour effectuer les tâches listées sur cette page, vous devez disposer du rôle Administrateur VirtualMachine du projet. Suivez les étapes pour valider ou demandez à votre administrateur IAM de projet de vous attribuer le rôle Administrateur VirtualMachine du projet (project-vm-admin) dans l'espace de noms du projet dans lequel réside la VM.
Pour les opérations sur les VM à l'aide de la console GDC ou de la CLI gdcloud, demandez à votre administrateur IAM de projet de vous attribuer le rôle Administrateur de machines virtuelles du projet et le rôle Lecteur du projet (project-viewer).
Arrêter une VM
Lorsque vous arrêtez une machine virtuelle (VM), l'hyperviseur libère toutes les ressources associées à l'instance. La VM est arrêtée.
Arrêtez une VM en cours d'exécution à l'aide de la console GDC ou de kubectl.
Console
Dans le menu de navigation, cliquez sur Machines virtuelles > Instances.
Dans la liste des VM, cochez la case correspondant à la VM en cours d'exécution que vous souhaitez arrêter.
Cliquez sur Arrêter.
Dans la boîte de dialogue de confirmation, cliquez sur Arrêter.
Recherchez le champ runningState dans le spec de la VM et remplacez sa valeur par Stopped. Si runningState ne figure pas dans spec, ajoutez runningState à spec et définissez la valeur sur Stopped.
Fichier kubeconfig du serveur de l'API Management.
MANAGEMENT_API_SERVER_NAME
Nom du serveur de l'API Management.
NAMESPACE
Espace de noms de la VM.
VM_NAME
Nom de la VM.
PROJECT
Nom du projet de la VM.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis guide details how to manage the lifecycle of virtual machines (VMs) by stopping, starting, and restarting them to support application needs.\u003c/p\u003e\n"],["\u003cp\u003eYou can modify a VM's configuration, such as vCPU count or memory, but the VM must be stopped before these changes can be applied and then must be power cycled for them to take effect.\u003c/p\u003e\n"],["\u003cp\u003eThe process of stopping a VM involves deallocating all resources associated with the instance, whereas starting a VM returns it from a stopped state to running.\u003c/p\u003e\n"],["\u003cp\u003eRestarting a VM resets it to its initial state and wipes the memory contents, essentially rebooting the system.\u003c/p\u003e\n"],["\u003cp\u003eTo perform these operations, you will need the Project VirtualMachine Admin role and use either the GDC console, \u003ccode\u003egdcloud\u003c/code\u003e CLI, or \u003ccode\u003ekubectl\u003c/code\u003e CLI.\u003c/p\u003e\n"]]],[],null,["# Start and stop a VM\n\nYou can stop, start, and restart VMs to support the lifecycle of your\napplications. For example, you might want to change the number of assigned\nvirtual centralized processing units (vCPUs) or the amount of memory allocated to\na VM. You must stop the VM before you edit the configuration. After you finish,\nyou must cycle the power state to apply the changes. This page provides instructions\nto stop, start, and restart your VMs in such processes.\n\nBefore you begin\n----------------\n\nTo use `gdcloud` command-line interface (CLI) commands, ensure that you have downloaded, installed,\nand configured the [`gdcloud` CLI](/distributed-cloud/hosted/docs/latest/gdch/resources/gdcloud-overview).\nAll commands for Distributed Cloud use the `gdcloud` or\n`kubectl` CLI, and require an operating system (OS) environment.\n\n### Get the kubeconfig file path\n\nTo run commands against the Management API server, ensure you have the following\nresources:\n\n1. [Sign in and generate](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/iam/sign-in#cli) the\n kubeconfig file for the Management API server if you don't have one.\n\n2. Use the path to the kubeconfig file of the Management API server to replace\n \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER\u003c/var\u003e in these instructions.\n\nIf you want to minimize your VM start up time, follow the directions in\n[Minimize the VM start time](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vms/manage-vms/operations-and-lifecycle/minimize-vm-start)\nbefore you start your VM.\n\n### Request permissions and access\n\nTo perform the tasks listed in this page, you must have the Project\nVirtualMachine Admin role. Follow the steps to either\n[verify](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vms/preparation#verify-user-access)\nor have your Project IAM Admin\n[assign](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/iam/role-bindings)\nyou the Project VirtualMachine Admin (`project-vm-admin`) role in the namespace\nof the project where the VM resides.\n\nFor VM operations using the GDC console or the gdcloud CLI,\nrequest your Project IAM Admin to assign you both the\nProject VirtualMachine Admin role and the Project Viewer (`project-viewer`)\nrole.xs\n\nStop a VM\n---------\n\nWhen you stop a virtual machine (VM), the hypervisor deallocates all resources\nassociated with the instance. The VM is shut down.\n\nStop a VM that's in a running state by using the GDC console or\n`kubectl`. \n\n### Console\n\n1. In the navigation menu, click **Virtual Machines \\\u003e Instances**.\n\n2. In the list of VMs, select the checkbox for the running VM that you want\n to stop.\n\n3. Click **Stop**.\n\n4. In the confirmation dialog, click **Stop**.\n\n### gdcloud\n\nTo stop a VM: \n\n gdcloud compute instances stop \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e --project \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n- Replace \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e with the name of the VM.\n- Replace \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e with the name of the GDC project in which the VM lives.\n\n### kubectl\n\n1. Run the following command:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e \\\n edit virtualmachines.virtualmachine.gdc.goog \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n -n \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n2. Look for the field `runningState` in the `spec` of the VM and change the value of the field to `Stopped`. If `runningState` is not in the `spec` add `runningState` to the `spec` and set the value to `Stopped`.\n\n spec:\n runningState: Stopped\n\n3. Verify the status of the VM:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e \\\n get virtualmachines.virtualmachine.gdc.goog \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n -n \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n Use these definitions for the preceding variables.\n\nStart a VM\n----------\n\nStart a VM from a stopped state by using the console or `kubectl`. \n\n### Console\n\n1. In the navigation menu, click **Virtual Machines \\\u003e Instances**.\n\n2. In the list of VMs, select the checkbox for the stopped VM that you want\n to start.\n\n3. Click **Start**.\n\n4. In the confirmation dialog, click **Start**.\n\n### gdcloud\n\nTo start a VM: \n\n gdcloud compute instances start \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e --project \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n- Replace \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e with the name of the VM.\n- Replace \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e with the name of the GDC project in which the VM lives.\n\n### kubectl\n\n1. Run the following command:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e \\ \n edit virtualmachines.virtualmachine.gdc.goog \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\ \n -n \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n2. Look for the field `runningState` in the `spec` of the VM and change the value of the field to `Running`.\n\n spec:\n runningState: Running\n\n3. Verify the VM status:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e \\\n get virtualmachines.virtualmachine.gdc.goog \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n -n \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n Use these definitions for the variables in the example code.\n\nRestart a VM\n------------\n\nWhen you restart a VM, the machine resets to its initial state and the memory\ncontents of the machine are wiped.\n\nRestart a VM that is in a running state by using the console or `kubectl`. \n\n### Console\n\n1. In the navigation menu, click **Virtual Machines \\\u003e Instances**.\n\n2. In the list of VMs, select the checkbox for the running VM that you want\n to restart.\n\n3. Click **Reset**.\n\n4. In the confirmation dialog, click **Reset**.\n\n### gdcloud\n\nTo reset a VM: \n\n gdcloud compute instances reset \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e --project \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n- Replace \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e with the name of the VM.\n- Replace \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e with the name of the GDC project in which the VM lives.\n\n### kubectl\n\n1. Get the client certificate and key data, and the Management API server.\n Use these values in the following steps:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e config view --raw -o \\\n jsonpath='{.users[?(@.name ==\"\u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_NAME\u003c/var\u003e-admin\")].user.client-certificate-data}' | \\\n base64 -d \u003e cert\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e config view --raw -o \\\n jsonpath='{.users[?(@.name == \"\u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_NAME\u003c/var\u003e-admin\")].user.client-key-data}' | \\\n base64 -d \u003e key\n export APISERVER=`kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e \\\n config view --raw -o \\\n jsonpath='{.clusters[?(@.name == \"\u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_NAME\u003c/var\u003e\")].cluster.server}'`\n\n2. Make an API request to restart the VM using the `wget` command and specify\n the certificate and key from the previous step:\n\n wget --method=PUT -O- --no-check-certificate --certificate cert --private-key key --content-on-error=on $APISERVER/apis/virtualmachineoperations.gdc.goog/v1/namespaces/\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e/virtualmachines/\u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e/restart\n\n3. Verify the VM status:\n\n kubectl --kubeconfig \u003cvar translate=\"no\"\u003eMANAGEMENT_API_SERVER_KUBECONFIG\u003c/var\u003e \\\n get virtualmachines.virtualmachine.gdc.goog \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e -n \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\n\n Use these definitions for the variables in the\n example code."]]