Quantcast
Channel: tech cottage
Viewing all articles
Browse latest Browse all 48

Create google cloud VM inside custom VPC remotely with gcloud command

$
0
0
These are the steps for creating VM instances inside a google cloud VPC custom network remotely. It assumes that google cloud account has been created and cloud sdk has been installed and working correctly.

1) Set google cloud project:

  • gcloud config set project [xxxxxxxxxxxxxxx]

2) Create custom VPC network
  • gcloud compute networks create vpc-net --subnet-mode custom
3) Create two subnets within the VPC network
  • gcloud compute networks subnets create vpc-net-subnet-us-central --network vpc-net --region us-central1 --range 10.0.1.0/24
  • gcloud compute networks subnets create vpc-net-subnet-eu-west --network vpc-net --region europe-west1 --range 10.0.2.0/24
4) Listing the created subnets
  • gcloud compute networks subnets list --network vpc-net
vpc-net-subnet-eu-west     europe-west1  vpc-net  10.0.2.0/24
vpc-net-subnet-us-central  us-central1   vpc-net  10.0.1.0/24

5) Create the VMs inside the subnets
  • gcloud compute instances create vpc-net-vm-us --subnet vpc-net-subnet-us-central --zone us-central1-a
  • gcloud compute instances create vpc-net-vm-eu --subnet vpc-net-subnet-eu-west --zone europe-west1-b


6) Try to ping (From local machine) or ssh (From gcloud web console) - it would fail.


7) Create the filewall rules for allowing ping & ssh to the newly created VMs.
  • gcloud compute firewall-rules create vpc-net-allow-ssh --allow tcp:22,icmp --network vpc-net
Now, we should be able to ping and ssh into the VMs.





Viewing all articles
Browse latest Browse all 48

Trending Articles