How to create a Virtual Machine instance on Google Compute Engine

Google Compute Engine(GCE) is a cloud computing platform that provides virtual machines, storage, networking, and other services. With flexible configurations and seamless integration with other Google Cloud services, it empowers businesses to efficiently manage their computing workloads in the cloud. Compute Engine is a cost-effective way to run your applications in the cloud. You only pay for the resources you use, and there are no upfront costs.

Creating a GCE VM

To create a Virtual Machine (VM) instance on Google Compute Engine, follow these steps:

  1. Create a Google Cloud Platform (GCP) account: If you don't have one, sign up for a GCP account. You may be eligible for free credits and resources for the first 12 months.

  2. Create a Project: In the Google Cloud Console, create a new project. Projects help organize and manage your GCP resources.

GCP project
GCP project
  1. Enable billing: Once you have a GCP account, you'll need to enable billing for your project. This step is necessary to use Google Compute Engine resources. You can set up billing information in the Google Cloud Console.

GCP billing
GCP billing
  1. Enable Compute Engine API: In the Cloud Console, navigate to the API & Services > Dashboard, and enable the Compute Engine API.

Compute Engine API
Compute Engine API
  1. Install the Google Cloud SDK: The gcloud command-line tool is part of the Google Cloud SDK. You'll need to install this SDK on your local machine to interact with GCP services. You can follow this Answer for installation purpose.

  2. Initialize gcloud and set up authentication: After installing the Google Cloud SDK, open your terminal and run the following command to initialize gcloud:

gcloud init
Command to initialize gcloud

Note: This command will guide you through the authentication process, where you'll need to log in with your Google Cloud account and choose a GCP project to work with. If you haven't created a project yet, you can create one during this process.

Output of running above command is:

Output of gcloud init command
Output of gcloud init command
  1. Create the VM instance: Now, you can use the gcloud compute instances create command to create your VM instance. Here's the basic syntax:

gcloud compute instances create INSTANCE_NAME \
--image-family=IMAGE_FAMILY \
--image-project=IMAGE_PROJECT \
--machine-type=MACHINE_TYPE \
--zone=ZONE
Command to create VM instance

Replace the placeholders:

  • INSTANCE_NAME with the desired name for your instance.

  • IMAGE_FAMILY with the name of the Linux image family you want to use (e.g., debian-11 or ubuntu-20-04).

  • IMAGE_PROJECT with the project name or ID that provides the Linux image (e.g., debian-cloud or ubuntu-os-cloud).

  • MACHINE_TYPE with the desired machine type for your instance (e.g., n1-standard-1 or e2-micro).

  • ZONE with the desired zone where you want to create the instance (e.g., us-central1-a or europe-west1-b).

Output of running above command is:

VM instance successfully created
VM instance successfully created

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved