After activating cloud shell, run the command below:
gcloud compute instances create gcelab2 --machine-type n1-standard-2 --zone <zone-name>
Replace the zone-name
with the name of the zone where you want your vm instance to run.
If you created an environment variable to store your zone, replace zone-name with that environment variable. For example:
gcloud compute instances create gcelab2 --machine-type n1-standard-2 --zone $ZONE
The output will look something like this:
Here are the command details:
gcloud compute
: This allows you to manage your Compute Engine resources in a format that's simpler than the Compute Engine API.instances create
: This creates a new instance.gcelab2
: is the name of the VM.The
--machine-type
flag: This specifies the machine type as n1-standard-2.The
--zone
flag: This specifies where the VM is created.
If you leave out the --zone
flag, the gcloud tool automatically sets the zone based on your default properties. Other required instance settings, such as machine type and image, are set to default values if not specified in the create command.
To open help
for the create command, run the following command:
gcloud compute instances create --help
Note: Press ENTER or the spacebar to scroll through the help content. To exit the content, type Q.
Connect to your VM instance with SSH
gcloud compute makes connecting to your instances easy. The gcloud compute ssh command provides a wrapper around SSH, which takes care of authentication and the mapping of instance names to IP addresses.
To connect to your VM with SSH, run the following command:
gcloud compute ssh gcelab2 --zone $ZONE
Output:
WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key.
This tool needs to create the directory
[/home/gcpstaging306_student/.ssh] before being able to generate SSH Keys.
Do you want to continue? (Y/n)
To continue, type Y.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase)
To leave the passphrase empty, press ENTER.
To disconnect, run the command below:
exit
You should be back at your project's command prompt.
There you go!!!!
Never stop creating and learning