You can stop, start, and restart VMs to support the lifecycle of your applications. For example, you might want to change the number of assigned virtual centralized processing units (vCPUs) or the amount of memory allocated to a VM. You must stop the VM before you edit the configuration. After you finish, you must cycle the power state to apply the changes. This page provides instructions to stop, start, and restart your VMs in such processes.
Before you begin
To use gdcloud command-line interface (CLI) commands, ensure that you have downloaded, installed,
and configured the gdcloud CLI.
All commands for Distributed Cloud use the gdcloud or
kubectl CLI, and require an operating system (OS) environment.
Get the kubeconfig file path
To run commands against the Management API server, ensure you have the following resources:
Sign in and generate the kubeconfig file for the Management API server if you don't have one.
Use the path to the kubeconfig file of the Management API server to replace
MANAGEMENT_API_SERVERin these instructions.
If you want to minimize your VM start up time, follow the directions in Minimize the VM start time before you start your VM.
Request permissions and access
To perform the tasks listed in this page, you must have the Project
VirtualMachine Admin role. Follow the steps to either
verify
or have your Project IAM Admin
assign
you the Project VirtualMachine Admin (project-vm-admin) role in the namespace
of the project where the VM resides.
For VM operations using the GDC console or the gdcloud CLI,
request your Project IAM Admin to assign you both the
Project VirtualMachine Admin role and the Project Viewer (project-viewer)
role.xs
Stop a VM
When you stop a virtual machine (VM), the hypervisor deallocates all resources associated with the instance. The VM is shut down.
Stop a VM that's in a running state by using the GDC console or
kubectl.
Console
In the navigation menu, click Virtual Machines > Instances.
In the list of VMs, select the checkbox for the running VM that you want to stop.
Click Stop.
In the confirmation dialog, click Stop.
gdcloud
To stop a VM:
gdcloud compute instances stop VM_NAME \
--project PROJECT
- Replace
VM_NAMEwith the name of the VM. - Replace
PROJECTwith the name of the GDC project in which the VM lives.
kubectl
Run the following command:
kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ -n PROJECT \ edit virtualmachines.virtualmachine.gdc.goog VM_NAMELook for the field
runningStatein thespecof the VM and change the value of the field toStopped. IfrunningStateis not in thespecaddrunningStateto thespecand set the value toStopped.spec: runningState: StoppedVerify the status of the VM:
kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ -n PROJECT \ get virtualmachines.virtualmachine.gdc.goog VM_NAMEUse these definitions for the preceding variables.
Variable Definition MANAGEMENT_API_SERVER_KUBECONFIGThe Management API server kubeconfig file. VM_NAMEThe VM's name. PROJECTThe VM's project name.
Start a VM
Start a VM from a stopped state by using the console or kubectl.
Console
In the navigation menu, click Virtual Machines > Instances.
In the list of VMs, select the checkbox for the stopped VM that you want to start.
Click Start.
In the confirmation dialog, click Start.
gdcloud
To start a VM:
gdcloud compute instances start VM_NAME --project PROJECT
- Replace
VM_NAMEwith the name of the VM. - Replace
PROJECTwith the name of the GDC project in which the VM lives.
kubectl
Run the following command:
kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ -n PROJECT \ edit virtualmachines.virtualmachine.gdc.goog VM_NAMELook for the field
runningStatein thespecof the VM and change the value of the field toRunning.spec: runningState: RunningVerify the VM status:
kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ -n PROJECT \ get virtualmachines.virtualmachine.gdc.goog VM_NAMEUse these definitions for the variables in the example code.
Variable Definition MANAGEMENT_API_SERVER_KUBECONFIGThe Management API server kubeconfig file. MANAGEMENT_API_SERVER_NAMEThe name of the Management API server. VM_NAMEThe VM's name. PROJECTThe VM's project name.
Restart a VM
When you restart a VM, the machine resets to its initial state and the memory contents of the machine are wiped.
Restart a VM that is in a running state by using the console or kubectl.
Console
In the navigation menu, click Virtual Machines > Instances.
In the list of VMs, select the checkbox for the running VM that you want to restart.
Click Reset.
In the confirmation dialog, click Reset.
gdcloud
To reset a VM:
gdcloud compute instances reset VM_NAME --project PROJECT
- Replace
VM_NAMEwith the name of the VM. - Replace
PROJECTwith the name of the GDC project in which the VM lives.
kubectl
Get the client certificate and key data, and the Management API server. Use these values in the following steps:
kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ config view --raw -o \ jsonpath='{.users[?(@.name =="MANAGEMENT_API_SERVER_NAME-admin")].user.client-certificate-data}' \ | base64 -d > cert kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ config view --raw -o \ jsonpath='{.users[?(@.name == "MANAGEMENT_API_SERVER_NAME-admin")].user.client-key-data}' \ | base64 -d > key export APISERVER=`kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ config view --raw -o \ jsonpath='{.clusters[?(@.name == "MANAGEMENT_API_SERVER_NAME")].cluster.server}'`Make an API request to restart the VM using the
wgetcommand and specify the certificate and key from the previous step:wget --method=PUT -O- \ --no-check-certificate \ --certificate cert \ --private-key key \ --content-on-error=on \ $APISERVER/apis/virtualmachineoperations.gdc.goog/v1/namespaces/PROJECT/virtualmachines/VM_NAME/restartVerify the VM status:
kubectl --kubeconfig MANAGEMENT_API_SERVER_KUBECONFIG \ -n PROJECT \ get virtualmachines.virtualmachine.gdc.goog VM_NAMEUse these definitions for the variables in the example code.
Variable Definition MANAGEMENT_API_SERVER_KUBECONFIGThe Management API server kubeconfig file. MANAGEMENT_API_SERVER_NAMEThe name of the Management API server. VM_NAMEThe VM's name. PROJECTThe VM's project name.