VM creation can be achieved using command-line tools. The equivalent of the previously described instance creation using Cloud Shell can be achieved using the following command line:
gcloud compute instances create instance-1 –project=wmarusiak-book-351718 –zone=europe-west1-b –machine-type=e2-medium –network-interface=network-tier=PREMIUM,subnet=default –maintenance-policy=MIGRATE –provisioning-model=STANDARD –create-disk=auto-delete=yes,boot=yes,device-name=instance-1,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20220419,mode=rw,size=50,type=projects/wmarusiak-book-351718/zones/europe-west1-b/diskTypes/pd-ssd
The preceding command specifies the following options:
- –project: The project in which we want to create the instance.
- –zone: The exact zone from the desired region.
- –machine-type: This can either be one of the pre-defined machine sizes (vCPU and RAM) or a custom one.
- –network-interface: This specifies the network tier and subnet.
- –maintenance-policy: This specifies what should happen with the VM if a maintenance event happens. Migrate causes live migration of a VM. Terminate stops a VM instead of migrating it.
- –provisioning-model: If you wish to use spot VMs, you should choose spot instead of a standard.
- –create-disk: This specifies what should happen with the instance disk when the instance deletion occurs. In this example, we can see the size of the disk as well as its type (HDD, SSD, or a balanced one).
The aforementioned options have multiple switches and allow for precise VM specification and configuration.
In the next section, we will edit the Google Compute instance to familiarize ourselves with options and command-line options.
Once an instance is created, we can start using it, install any application, and configure it to our needs. However, sometimes, we need to change some settings, add disks, or change the network to which our instance is attached.
For example, let’s start with some information about a running instance.
The running VM inventory
The easiest way to find out the details of an instance is to navigate to the Cloud console and view its details.
Console
In the Cloud console, we can click on the desired instance and view various details about the instance.
We have visible four sections on the instance details page, which are listed as follows:
- Details: The screen that displays the main information. We can see basic information (name, instance ID, creation time, and so on) as well as machine configuration, disks, and networking information.
- Observability: Initial monitoring information about the instance, which is live-updated. By default, we see metrics such as CPU utilization and network traffic. It is possible to collect and visualize even more metrics by installing the Ops Agent.
- Os Info: This is a part of VM Manager, a suite of tools that can be used to manage operating systems at scale. It requires OS Config Agent and VM Manager API enablement to be installed on the instances. Once enabled, it displays information about available patches, vulnerabilities, and installed packages.
- Screenshot: This can be used to see a screenshot of the instance in the Cloud console, provided that the display device setting is enabled on the instance.
By viewing this information in the Cloud console, we can easily find details about the instance, its configuration, and possible issues.
Command line
Similar, if not even more, detailed information about an instance can be retrieved by executing the following command:
gcloud compute instances describe INSTANCE_NAME –zone=INSTANCE_ZONE
The output of this command is long and detailed, so we encourage you to run the command yourself and try to find information about the boot disk, image, instance type, and networking.