Skip to content

Latest commit

 

History

History
168 lines (111 loc) · 2.93 KB

File metadata and controls

168 lines (111 loc) · 2.93 KB

GSP002 - Getting Started with Cloud Shell and gcloud

Task 1. Configuring your environment

  1. Set Default Region

    gcloud config set compute/region us-central1
  2. Cek Region

    gcloud config get-value compute/region
  3. Setting environment variables

    export PROJECT_ID=$(gcloud config get-value project)
    export ZONE=$(gcloud config get-value compute/zone)
    

Creating a virtual machine with the gcloud tool

  1. Create VM

    gcloud compute instances create gcelab2 --machine-type e2-medium --zone $ZONE
    • instances create creates a new instance.

    • gcelab2 is the name of the VM.

    • The --machine-type flag specifies the machine type as e2-medium.

    • The --zone flag specifies where the VM is created.

  2. Help Command

    gcloud compute instances create --help

Exploring gcloud commands

  1. Help Command

    gcloud -h
    gcloud config --help
  2. View configuration in environment variables

    gcloud config list
    gcloud config list --all
  3. View all Components

    gcloud components list

Task 2. Filtering command-line output

  1. Lihat semua instances

    gcloud compute instances list
  2. Lihat instance tertentu

    gcloud compute instances list --filter="name=('gcelab2')"
  3. Firewall rules

    gcloud compute firewall-rules list
    gcloud compute firewall-rules list --filter="network='default'"
    gcloud compute firewall-rules list --filter="NETWORK:'default' AND ALLOW:'icmp'"

Task 3. Connecting to your VM instance

  1. SSH to VM

    gcloud compute ssh gcelab2 --zone $ZONE
  2. Exit SSH

    exit

Task 4. Updating the firewall

  1. Lihat firewall rules

    gcloud compute firewall-rules list
  2. Tambah tag

    gcloud compute instances add-tags gcelab2 --tags http-server,https-server
  3. Edit firewall rules

    gcloud compute firewall-rules create default-allow-http --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=http-server
  4. Cek firewall

    gcloud compute firewall-rules list --filter=ALLOW:'80'
  5. Cek Apakah bisa diakses

    curl http://$(gcloud compute instances list --filter=name:gcelab2 --format='value(EXTERNAL_IP)')

Task 5. Viewing the system logs

  1. Lihat log

    gcloud compute instances get-serial-port-output gcelab2 --zone $ZONE
  2. Dengan filter

    gcloud logging logs list --filter="compute"
    gcloud logging read "resource.type=gce_instance" --limit 5
    gcloud logging read "resource.type=gce_instance AND labels.instance_name='gcelab2'" --limit 5