Skip to main content

Create virtual machines with Google Cloud Shell and remove them

In this article, we'll walk you step-by-step through creating virtual machines (VMs) using Google Cloud Shell and removing GCE VMs with the gcloud command. If you have a basic understanding of Google Cloud, you're in the right place to find out how quick and easy it is to start a VM instance directly from the terminal, without the need to use the Google Cloud Console GUI.

What is Google Cloud Shell?

Google Cloud Shell is an integrated management environment that allows you to run commands directly on Google Cloud. This environment is preconfigured with gcloud and other tools, allowing you to work on Google Cloud projects quickly and without having to install any software on your computer.

Prerequisites

Before you get started, make sure you have the following prerequisites:

  • An active Google Cloud account
  • Access to Google Cloud Shell
  • Enabled the Google Compute Engine GCE

Create virtual machines with Google Cloud Shell

Follow these simple steps to create virtual machines using only Google Cloud Shell:

  1. Access Google Cloud Shell (you will be automatically directed to the Cloud Shell environment).
  2. Make sure that your Google Cloud project is set up correctly by running the following command:

    gcloud config set project [ID_DEL_TEL_Your_PROJECT]
  3. Check that the Compute Engine service is enabled with the command:

    gcloud services enable compute.googleapis.com
  4. Now create a VM instance in the Milan region (zone europe-west8-a) by running the following command:

    gcloud compute instances create my-vm \
    	--zone=europe-west8-a \
    	--machine-type=e2-medium \
    	--image-family=debian-12 \
            	--image-project=debian-cloud
    Created [https://www.googleapis.com/compute/v1/projects/[ID_DEL_TEL_YOUR_PROJECT]/zones/europe-west8-a/instances/my-vm].
    NAME: my-vm
    ZONE: europe-west8-a
    MACHINE_TYPE: e2-medium
    STATUS: RUNNING
  5. Once the VM is created, you can list all VM instances present with:

    gcloud compute instances list
  6. Now you can connect using the SSH command directly from the Cloud Shell:

    gcloud compute ssh my-vm --zone=europe-west8-a

Remove virtual machines with Google Cloud Shell

  1. List all VM instances present with:

    gcloud compute instances list
  2. Identified the VM to be deleted use this command to remove it:

    gcloud compute instances delete my-vm --zone=europe-west8-a
    The following instances will be deleted. Any attached disks configured to be auto-deleted will be
    deleted unless they are attached to any other instances or the `--keep-disks` flag is given and
    specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost.
     - [my-vm] in [europe-west8-a].
    Do you want to continue (Y/n)?  Y

Frequently Asked Questions (FAQ)

1. Can you change the configuration of a VM once it is created?

Yes, you can change your VM settings such as machine type, disk space, and other options via Google Cloud Shell using gcloud commands or from the Google Cloud Console.

2. How much does it cost to use Google Cloud Shell?

Google Cloud Shell is free for up to 50 hours per month. However, the resources you create, such as VMs, may generate additional costs based on Google Cloud fees.

3. Can I create VMs with operating systems other than Debian?

Yes, you can choose different operating system images such as Ubuntu, CentOS, Windows, and others by specifying the parameters --image-family and --image-project in the VM creation command.

Find out more about our Google Cloud Consultation

Get a expert Google Cloud support to manage your VMs and services. Free 30m Now!

Add new comment

Comment

  • Allowed HTML tags: <br> <p> <code class="language-*"> <pre>
  • Lines and paragraphs break automatically.
  • Only images hosted on this site may be used in <img> tags.