PolarSPARC

Essential Cloud Infrastructure: Foundation - Summary Notes - Part 1


Bhaskar S 10/20/2019


Using Google Cloud Platform (GCP)

Virtual Private Cloud (VPC)

Hands-on with gcloud

List all the available GCP Regions

gcloud compute regions list

The following will be the typical output:

Output.1

NAME                     CPUS  DISKS_GB  ADDRESSES  RESERVED_ADDRESSES  STATUS  TURNDOWN_DATE
asia-east1               0/24  0/4096    0/8        0/8                 UP
asia-east2               0/24  0/4096    0/8        0/8                 UP
asia-northeast1          0/24  0/4096    0/8        0/8                 UP
asia-northeast2          0/24  0/4096    0/8        0/8                 UP
asia-south1              0/24  0/4096    0/8        0/8                 UP
asia-southeast1          0/24  0/4096    0/8        0/8                 UP
australia-southeast1     0/24  0/4096    0/8        0/8                 UP
europe-north1            0/24  0/4096    0/8        0/8                 UP
europe-west1             0/24  0/4096    0/8        0/8                 UP
europe-west2             0/24  0/4096    0/8        0/8                 UP
europe-west3             0/24  0/4096    0/8        0/8                 UP
europe-west4             0/24  0/4096    0/8        0/8                 UP
europe-west6             0/24  0/4096    0/8        0/8                 UP
northamerica-northeast1  0/24  0/4096    0/8        0/8                 UP
southamerica-east1       0/24  0/4096    0/8        0/8                 UP
us-central1              0/24  0/4096    0/8        0/8                 UP
us-east1                 0/24  0/4096    0/8        0/8                 UP
us-east4                 0/24  0/4096    0/8        0/8                 UP
us-west1                 0/24  0/4096    0/8        0/8                 UP
us-west2                 0/24  0/4096    0/8        0/8                 UP

List GCP Project details

gcloud config list

Switch to a GCP Project called my-gcp-polarsparc

gcloud config set project my-gcp-polarsparc

Create a Custom VPC Network called privatenet

gcloud compute networks create privatenet --subnet-mode=custom

The following will be the typical output:

Output.2

Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-00-5bbfa70ed771/global/networks/privatenet].
NAME        SUBNET_MODE  BGP_ROUTING_MODE  IPV4_RANGE  GATEWAY_IPV4
privatenet  CUSTOM       REGIONAL

Instances on this network will not be reachable until firewall rules
are created. As an example, you can allow all internal traffic between
instances as well as SSH, RDP, and ICMP by running:

$ gcloud compute firewall-rules create <FIREWALL_NAME> --network privatenet --allow tcp,udp,icmp --source-ranges <IP_RANGE>
$ gcloud compute firewall-rules create <FIREWALL_NAME> --network privatenet --allow tcp:22,tcp:3389,icmp

Create a Subnet called privatesubnet-us under the custom Network privatenet with the IP address range 172.16.0.0/24

gcloud compute networks subnets create privatesubnet-us --network=privatenet --region=us-central1 --range=172.16.0.0/24

The following will be the typical output:

Output.3

Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-00-5bbfa70ed771/regions/us-central1/subnetworks/privatesubnet-us].
NAME              REGION       NETWORK     RANGE
privatesubnet-us  us-central1  privatenet  172.16.0.0/24

List the available VPC Networks

gcloud compute networks list

The following will be the typical output:

Output.4

NAME           SUBNET_MODE  BGP_ROUTING_MODE  IPV4_RANGE  GATEWAY_IPV4
managementnet  CUSTOM       REGIONAL
mynetwork      CUSTOM       REGIONAL
privatenet     CUSTOM       REGIONAL

List the available VPC Subnets sorted by VPC Network

gcloud compute networks subnets list --sort-by=NETWORK

The following will be the typical output:

Output.5

NAME                 REGION                   NETWORK        RANGE
managementsubnet-us  us-central1              managementnet  10.130.0.0/20
mynetwork            us-west2                 mynetwork      10.168.0.0/20
mynetwork            asia-northeast1          mynetwork      10.146.0.0/20
mynetwork            asia-northeast2          mynetwork      10.174.0.0/20
mynetwork            us-west1                 mynetwork      10.138.0.0/20
mynetwork            southamerica-east1       mynetwork      10.158.0.0/20
mynetwork            europe-west6             mynetwork      10.172.0.0/20
mynetwork            europe-west4             mynetwork      10.164.0.0/20
mynetwork            asia-east1               mynetwork      10.140.0.0/20
mynetwork            europe-north1            mynetwork      10.166.0.0/20
mynetwork            asia-southeast1          mynetwork      10.148.0.0/20
mynetwork            us-east4                 mynetwork      10.150.0.0/20
mynetwork            europe-west1             mynetwork      10.132.0.0/20
mynetwork            europe-west2             mynetwork      10.154.0.0/20
mynetwork            europe-west3             mynetwork      10.156.0.0/20
mynetwork            australia-southeast1     mynetwork      10.152.0.0/20
mynetwork            asia-south1              mynetwork      10.160.0.0/20
mynetwork            us-east1                 mynetwork      10.142.0.0/20
mynetwork            us-central1              mynetwork      10.128.0.0/20
mynetwork            asia-east2               mynetwork      10.170.0.0/20
mynetwork            northamerica-northeast1  mynetwork      10.162.0.0/20
privatesubnet-eu     europe-west1             privatenet     172.20.0.0/20
privatesubnet-us     us-central1              privatenet     172.16.0.0/24

Create an ingress Firewall Rule called privatenet-allow-icmp-ssh-rdp for the custom Network privatenet allowing ICMP, SSH, and RDP traffic from all sources

gcloud compute firewall-rules create privatenet-allow-icmp-ssh-rdp --direction=INGRESS --priority=1000 --network=privatenet --action=ALLOW --rules=icmp,tcp:22,tcp:3389 --source-ranges=0.0.0.0/0

The following will be the typical output:

Output.6

Creating firewall...
Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-00-5bbfa70ed771/global/firewalls/privatenet-allow-icmp-ssh-rdp].
Creating firewall...done.
NAME                           NETWORK     DIRECTION  PRIORITY  ALLOW                 DENY  DISABLED
privatenet-allow-icmp-ssh-rdp  privatenet  INGRESS    1000      icmp,tcp:22,tcp:3389        False

List all the Firewall Rules sorted by VPC Network

gcloud compute firewall-rules list --sort-by=NETWORK

The following will be the typical output:

Output.7

NAME                              NETWORK        DIRECTION  PRIORITY  ALLOW                 DENY  DISABLED
managementnet-allow-icmp-ssh-rdp  managementnet  INGRESS    1000      tcp:22,tcp:3389,icmp        False
mynetwork-allow-icmp              mynetwork      INGRESS    65534     icmp                        False
mynetwork-allow-internal          mynetwork      INGRESS    65534     all                         False
mynetwork-allow-rdp               mynetwork      INGRESS    65534     tcp:3389                    False
mynetwork-allow-ssh               mynetwork      INGRESS    65534     tcp:22                      False
privatenet-allow-icmp-ssh-rdp     privatenet     INGRESS    1000      icmp,tcp:22,tcp:3389        False

To show all fields of the firewall, please show in JSON format: --format=json
To show all fields in table format, please see the examples in --help.

Create a VM instance called privatenet-us-vm in the subnet privatesubnet-us and in the Zone us-central1-c

gcloud compute instances create privatenet-us-vm --zone=us-central1-c --machine-type=f1-micro --subnet=privatesubnet-us

The following will be the typical output:

Output.8

Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-00-5bbfa70ed771/zones/us-central1-c/instances/privatenet-us-vm].
NAME              ZONE           MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP    STATUS
privatenet-us-vm  us-central1-c  f1-micro                   172.16.0.2   35.193.94.222  RUNNING

List all the VM instances sorted by Zone

gcloud compute instances list --sort-by=ZONE

The following will be the typical output:

Output.9

NAME                 ZONE            MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP      STATUS
mynet-eu-vm          europe-west1-b  f1-micro                   10.132.0.2   35.205.146.253   RUNNING
managementnet-us-vm  us-central1-c   f1-micro                   10.130.0.2   34.66.6.150      RUNNING
mynet-us-vm          us-central1-c   f1-micro                   10.128.0.2   104.154.222.250  RUNNING
privatenet-us-vm     us-central1-c   f1-micro                   172.16.0.2   35.193.94.222    RUNNING

References

Coursera - Essential Cloud Infrastructure: Foundation



© PolarSPARC