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 org admin cluster, ensure you have the following resources:
Locate the org admin cluster name, or ask your Platform Administrator (PA) what the cluster name is.
Sign in and generate the kubeconfig file for the org admin cluster if you don't have one.
Use the path to the kubeconfig file of the org admin cluster to replace
ORG_ADMIN_KUBECONFIG
in 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_NAME
with the name of the VM. - Replace
PROJECT
with the name of the GDC project in which the VM lives.
kubectl
Run the following command:
kubectl --kubeconfig ORG_ADMIN_KUBECONFIG \ edit virtualmachines.virtualmachine.gdc.goog VM_NAME \ -n PROJECT
Look for the field
runningState
in thespec
of the VM and change the value of the field toStopped
. IfrunningState
is not in thespec
addrunningState
to thespec
and set the value toStopped
.spec: runningState: Stopped
Verify the status of the VM:
kubectl --kubeconfig ORG_ADMIN_KUBECONFIG \ get virtualmachines.virtualmachine.gdc.goog VM_NAME \ -n PROJECT
Use these definitions for the preceding variables.
Variable Definition ORG_ADMIN_KUBECONFIG
The kubeconfig
path.VM_NAME
The VM's name. PROJECT
The 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_NAME
with the name of the VM. - Replace
PROJECT
with the name of the GDC project in which the VM lives.
kubectl
Run the following command:
kubectl --kubeconfig ORG_ADMIN_KUBECONFIG \ edit virtualmachines.virtualmachine.gdc.goog VM_NAME \ -n PROJECT
Look for the field
runningState
in thespec
of the VM and change the value of the field toRunning
.spec: runningState: Running
Verify the VM status:
kubectl --kubeconfig ORG_ADMIN_KUBECONFIG \ get virtualmachines.virtualmachine.gdc.goog VM_NAME \ -n PROJECT
Use these definitions for the variables in the example code.
Variable Definition ORG_ADMIN_KUBECONFIG
The kubeconfig
path.CLUSTER_NAME
The name of the org admin cluster. NAMESPACE
The VM namespace. VM_NAME
The VM's name. PROJECT
The 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_NAME
with the name of the VM. - Replace
PROJECT
with the name of the GDC project in which the VM lives.
kubectl
Get the client certificate and key data, and the org admin cluster's API server. Use these values in the following steps:
kubectl --kubeconfig ORG_ADMIN_KUBECONFIG config view --raw -o \ jsonpath='{.users[?(@.name =="CLUSTER_NAME-admin")].user.client-certificate-data}' | \ base64 -d > cert kubectl --kubeconfig ORG_ADMIN_KUBECONFIG config view --raw -o \ jsonpath='{.users[?(@.name == "CLUSTER_NAME-admin")].user.client-key-data}' | \ base64 -d > key export APISERVER=`kubectl --kubeconfig ORG_ADMIN_KUBECONFIG \ config view --raw -o \ jsonpath='{.clusters[?(@.name == "CLUSTER_NAME")].cluster.server}'`
Make an API request to restart the VM using the
wget
command 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/restart
Verify the VM status:
kubectl --kubeconfig ORG_ADMIN_KUBECONFIG \ get virtualmachines.virtualmachine.gdc.goog VM_NAME -n PROJECT
Use these definitions for the variables in the example code.
Variable Definition ORG_ADMIN_KUBECONFIG
The kubeconfig
path.CLUSTER_NAME
The name of the org admin cluster. NAMESPACE
The VM namespace. VM_NAME
The VM's name. PROJECT
The VM's project name.