Software Development

Creating a VM Instance in Different Zones Using The Cloud Shell on GCP

You may explore and learn about Google Cloud using the interactive shell environment known as Cloud Shell, and you can also manage your projects and resources from a web browser.

The Google Cloud CLI and other tools you require are already installed, fully authorized, current, and constantly accessible with Cloud Shell. You can design, build, debug, and deploy all of your cloud-based apps using Cloud Shell’s integrated code editor, which has a Cloud Code experience. On a Cloud Shell virtual machine instance, you may also start interactive tutorials, access cloned repositories, and evaluate web applications.

What is Cloud Shell?

Cloud Shell is a web-based interactive shell environment for Google Cloud that allows you to study and experiment with the service while also managing your projects and resources.

The Google Cloud CLI and other utilities you require are pre-installed, fully authorized, up-to-date, and always available when you need them with Cloud Shell. 

Cloud Shell has an integrated code editor with Cloud Code, allowing you to design, build, debug, and deploy your cloud-based apps fully in the cloud. You may also run interactive tutorials on a Cloud Shell virtual machine instance, browse cloned repositories, and evaluate web apps.

How to Create VM Instance?

We will create and edit VM instance using the command line

Let’s create a brand new VM instance

Let’s pretend you’ve used this UI to configure this virtual machine exactly how you want it.

You can find the identical address or command line command to set up the VM with the exact settings you specified at the very bottom.

How to Create an Instance Using Cloud Shell?

You can use this command within the script to create multiple VM instances with the same configuration. Let’s create an instance using Cloud Shell.

Shall we start with some simple, detailed commands for it?

gcloud compute instances create new-instance –zone us-central1-a

First, the command for this is, as you can see on screen, g cloud compute instances to create a new VM instance.

The name of that instance is another instance, and we want it to be in the US.

Once this instance has been created, you can see the resultant status on the cloud shell as well.

You can also refresh your browser window and see the instance on your Web console.

gcloud compute instances create –help

Running help on this cloud computing instance, create a command to show you all the available options.

This is fantastic for quick lookups, but if you want to really personalize your instance and have a lot of parameters, you should specify them on the Web console, build the command line, and then utilize it.

How to Set Some Default Values?

You can also set up some default values in your configuration file so that any new instances you create will use these default values.


gcloud config set compute/zone us-central1-c

For example, if you set the default zone to be US central one, see all new instances will be created in the zone.

gcloud compute instances create new-instance2

Try this out with another instance, do not specify the zone explicitly; you’ll find that this instance will be created in the US central one seat.

If you refresh your Web console, you’ll see that another instance, too, is in the US central one, New Zone was explicitly specified on the command line.

Now, let’s say I wanted to fit into the first instance we set up called another bash instance.

If you notice that my ssh command has failed, that’s because this instance was not found in the current zone.

Another instance is in a different zone, so you need to explicitly specify the — zone parameter when you want to fetch into it.

But if you want to fit into another instance in the default zone specified in the configuration, you do not need to specify the additional — zone parameter.

The zone is automatically picked up from your configuration file, and this command will succeed.

You can get the parameters for this Gcloud command by simply setting up the configuration on your Web console and clicking on the command line at the very bottom. If you want to create a number of virtual machines with specialized configurations in an automated way, you’ll script it using the Gcloud command-line utility.

Author

Henry Watson

Leave a comment

Your email address will not be published.