-
Set Default Region
gcloud config set compute/region us-central1
-
Cek Region
gcloud config get-value compute/region
-
Setting environment variables
export PROJECT_ID=$(gcloud config get-value project) export ZONE=$(gcloud config get-value compute/zone)
-
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 typeas e2-medium
. -
The
--zone
flag specifies where the VM is created.
-
-
Help Command
gcloud compute instances create --help
-
Help Command
gcloud -h
gcloud config --help
-
View configuration in environment variables
gcloud config list
gcloud config list --all
-
View all Components
gcloud components list
-
Lihat semua instances
gcloud compute instances list
-
Lihat instance tertentu
gcloud compute instances list --filter="name=('gcelab2')"
-
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'"
-
SSH to VM
gcloud compute ssh gcelab2 --zone $ZONE
-
Exit SSH
exit
-
Lihat firewall rules
gcloud compute firewall-rules list
-
Tambah tag
gcloud compute instances add-tags gcelab2 --tags http-server,https-server
-
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
-
Cek firewall
gcloud compute firewall-rules list --filter=ALLOW:'80'
-
Cek Apakah bisa diakses
curl http://$(gcloud compute instances list --filter=name:gcelab2 --format='value(EXTERNAL_IP)')
-
Lihat log
gcloud compute instances get-serial-port-output gcelab2 --zone $ZONE
-
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