Adding a GPU when a VM is created isn’t any different from creating a normal VM.
To add a GPU to the VM, choose the GPU VM under Machine family. Once selected, you can specify the VM type and choose the desired amount of vCPUs, RAM, and GPUs:
Figure 4.24 – A GPU added to the VM during the creation process
Once the VM is created, you can check in the VM settings that the GPU has been added, and then you can start using it:
Figure 4.25 – The VM with GPU added
It is recommended to check the GPU quota in the desired region and increase it to meet your demands.
Command line
The following commandlet allows us to create a GPU-based VM:
gcloud compute instances create VM_NAME \
–project PROJECT_ID \
–zone us-central1-c \
–machine-type a2-highgpu-1g \
–maintenance-policy TERMINATE –restart-on-failure \
–image-family centos-7 \
–image-project centos-cloud \
–boot-disk-size 200GB \
–boot-disk-type pd-ssd
After creating the VM instance, installing the NVIDIA and CUDA drivers might be necessary in order to allow us to fully use the GPU’s power.
Creating an instance template
An instance template is a resource that can be used to create individual instances or used in managed instance groups. It defines lots of information such as the machine type, the boot disk image, labels, start-up scripts, and other properties.
Console
The creation of an instance template is very similar to the creation of a single instance.
Please refer to the Creating GCE section for the details. The only difference between a single instance and a template is that the template is free and can be used with managed instance groups.
Command line
The command used to create an instance template differs from the one used to create a single instance:
gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME
The instance-templates namespace has many switches and configuration options, so we highly recommend reading through the Cloud SDK reference and trying to make a one-instance template by using a command-line interface.
The following link describes the gcloud command switches and allows us to choose appropriate options to create an instance template: https://cloud.google.com/sdk/gcloud/reference/compute/instance-templates/create.
Connecting remotely to a VM
Remote management of instances is a critical topic. It is not only complex but also important from a security point of view. We have all heard about big companies having their clouds hacked, so we should try to ensure that we access instances securely.
We will connect to two types of instances – Linux and Windows. We will access Linux instances using SSH keys (no username and password access) and the SSH protocol, which uses network port 22. Windows Server instances can be accessed using a native protocol called Remote Desktop Protocol (RDP), which uses network port 3389.
We must allow the required network port in the firewall table to access instances remotely. Firewalls will be discussed in more detail in upcoming chapters, but we must remember to allow network traffic in the VPC Firewall table to connect.