“Getting Started with Cloud Shell and gcloud”
Daftar Isi
Pengantar
Cloud Shell memberi Anda akses baris perintah ke resource komputasi yang dihosting di Google Cloud. Cloud Shell adalah mesin virtual berbasis Debian dengan direktori utama persisten sebesar 5 GB, yang memudahkan Anda mengelola project dan resource Google Cloud. Alat command line gcloud dan utilitas lain yang Anda perlukan telah diinstal sebelumnya di Cloud Shell, yang memungkinkan Anda untuk bangun dan berjalan dengan cepat.
Solusi
Task 1. Configure your environment
- Setting Region
gcloud config set compute/region
gcloud config get-value compute/region
- Cek Project
gcloud config get-value project
- Detail Project
gcloud compute project-info describe --project $(gcloud config get-value project)
- Setting environment variable
export PROJECT_ID=$(gcloud config get-value project)
export ZONE=$(gcloud config get-value compute/zone)
echo -e "PROJECT ID: $PROJECT_ID\nZONE: $ZONE"
- Create VM
gcloud compute instances create gcelab2 --machine-type e2-medium --zone $ZONE gcloud compute instances create --help
- gcloud Command
gcloud -h
gcloud config --help
gcloud help config
gcloud config list
gcloud config list --all
gcloud components list
Task 2. Filtering command line output
- Cek list
gcloud compute instances list gcloud compute instances list --filter="name=('gcelab2')" 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
- gunakan perintah berikut
gcloud compute ssh gcelab2 --zone $ZONE
sudo apt install -y nginx
Task 4. Updating the Firewall
- Cek list firewall
gcloud compute firewall-rules list
- tambahkan tag ke virtual machine
gcloud compute instances add-tags gcelab2 --tags http-server,https-server
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
gcloud compute firewall-rules list --filter=ALLOW:'80'
curl http://$(gcloud compute instances list --filter=name:gcelab2 --format='value(EXTERNAL_IP)')
Task 5. Viewing the system logs
- Cek log
gcloud logging logs list 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
Penutup
Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Getting Started with Cloud Shell and gcloud. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.