Google Cloud Platform – Day 1

Google Cloud Platform

All Google Cloud Products: https://cloud.google.com/products

IAM – Roles: https://cloud.google.com/iam/docs/understanding-roles

GCloud CLI: https://cloud.google.com/sdk/gcloud

Danh sách regions và zones: https://cloud.google.com/compute/docs/regions-zones

  • Về command gcloud:

Mỗi lần hoạt động trên console google cloud, nếu không muốn phải thêm param –zone hoặc –region thì:

1. Set the project region for this lab:
gcloud config set compute/region us-central1

2. Create a variable for region:
export REGION=us-central1

3. Create a variable for zone:
export ZONE=us-central1-c

Nếu dùng gcloud đã setup trên máy tính, thì ko cần thực hiện hành động trên nhiều lần.

Câu lệnh dùng để tạo 1 vm instance với config như hình bằng gcloud command:

gcloud compute instances create gcelab --machine-type e2-medium --zone=$ZONE

SSH vào vm instance:

gcloud compute ssh gcelab --zone=$ZONE
  • Một số ví dụ về gcloud command:
1. Set zone:
gcloud config set compute/zone ZONE

2. Get zone:
gcloud config get-value compute/zone

3. Get project id:
gcloud config get-value project

4. Get details project:
gcloud compute project-info describe --project $(gcloud config get-value project)

5. Tạo environment variable cho project id và zone:
export PROJECT_ID=$(gcloud config get-value project)
export ZONE=$(gcloud config get-value compute/zone)

6. Kiểm tra thử
echo -e "PROJECT ID: $PROJECT_ID\nZONE: $ZONE"

7. List firewall rules trong project:
gcloud compute firewall-rules list
gcloud compute firewall-rules list --filter="network='default'"
gcloud compute firewall-rules list --filter="NETWORK:'default' AND ALLOW:'icmp'"

8. Thêm 1 firewall rule:
gcloud compute instances add-tags gcelab2 --tags http-server,https-server (Vì sao phải add tag?)
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'

9. Xem 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

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *