Documents
Google Cloud Platform Services 基礎編
【GCP】Associate Cloud Engineer - 学習記録
gcloud interactive shell
The gcloud interactive shell provides a richer bash experience, simplifying command and documentation discovery with as-you-type autocompletion and help text snippets.
https://cloud.google.com/sdk/docs/interactive-gcloud
Core
Set default zone for compute engine
gcloud config set compute/zone us-east-1a
Enable compute engine API
gcloud services enable compute
Failed to negotiate an api version (error message)
gcloud auth application-default login
List all the deployments deployed on Google Cloud Deployment Manager
gcloud deployment-manager deployments list
Give details abount the components, libraries, system details and the log directory.
gcloud info ...
Computing Services
A/B testing
gcloud app services set-traffic [APP_NAME] splits 1=.5,2=.5 split-by cookie
Move all traffic
gcloud app services set-traffic [APP_NAME] splits 2=1 --migrate
Show image family names
gcloud compute images list
Create cloud functions
glcoud functions deploy ...
Adds keys to the instances one at a time.
gcloud compute project-info add-metadata ...
Automatically upload a key for your and SSH into the instance
gcloud compute ssh ...
List the firewall rules of network3
gcloud compute firewall-rules list --filter network=network3
Create firewall rule for windows remote access
gcloud compute firewall-rules create "[RULE_NAME]" --network "[NETWORK_NAME]" --allow tcp:3389
Use to SSH into the server from public end
gcloud compute ssh [USERNAME]@[SERVERNAME]
View the details of a custom subnet
gcloud compute networks subnets describe [SUBNET_NAME] --region us-central1
New a ubuntu instance with NVIDIA Tesla k80 GPU in us-east1-d zone
gcloud compute instances create gpu-instance-1 --machine-type n1-standard-2 \
--zone us-east1-d --accelerator type=nvidia-tesla-k80,count=1 \
--image-falimy ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --restart-on-failure
Create a vm with 4 CPUs
gcloud compute instances create --machine-type=n1-standard-4 [NAME]
Fetch metadata of instance
curl metadata.google.internal/computeMetadata/v1/
Run a check on network connectivity
gcloud info -run-diagnostics
Google Kubernetes Engine
kubeconfig get credential
gcloud container cluster get-credentials
Autoscale a replication controller with max 10 pods when cpu reaches 80%
kubectl autoscale rc [NAME] --max=10 --cpu-percentage=80
Delete kubernetes pods what are no longer needed.
kubectl delete deployment
Get the list of nodes along with tainted nodes
kubectl get nodes
Expose to public internet using a load balancer on port 80 to port 8080
kubectl expose deployment [DEPLOYMENT_NAME] --type LoadBalancer --port 80 --target-port 8080
Create a cluster with 4 nodes
gcloud container clusters create [CLUSTER_NAME] --num-nodes=4
Display the merged kubeconfig settings or a specified kubeconfig file
kubectl config view
Access to the kubernetes container
kubectl exec -it [CLUSTER_NAME] /bin/bash
Resize kubernetes nodes
gcloud container clusters resize [CLUSTER_NAME] --size [NUM]
Google Cloud Storage
Set the CORS configuration on the bucket
gsutil cors set ...
Ensure metadata has been updated that object in Cloud Storage.
gsutil stat gs://[BUCKET_NAME]/[OBJECT_NAME]
Change the storage class of an object in Cloud Storage
gsutil rewrite -s [STORAGE_CLASS] gs://[BUCKET_NAME]/[OBJECT_NAME]
Make a file public in cloud storage
gsutil acl ch -u allUsers:r gs://[BUCKET_NAME]/[FILE_NAME]
Enable versioning on bucket
gsutil versioning set on gs://[BUCKET_NAME]
Create bucket of nearline
gsutil mb -c nearline gs://[BUCKET_NAME]
Google IAM service
Copy existing roles across project
gcloud iam roles copy ...
List the active account name
gcloud auth list
Disable a custom role editor from the project
gcloud iam roles update editor --project [PROJECT_ID] --stage disabled
Add a IAM user
gcloud projects add-iam-policy-binding [PROJECT_NAME] --member "[MAIL_ADDRESS]" --role "roles/editor"
Create a IAM role
gcloud iam roles create viewer-role --project [PROJECT_NAME] --file [FILENAME].yaml