DevOps Buzz
Search…
Bash / Shell
Bitbucket
Distros
Elasticsearch
General
Guidelines / Standards
microk8s
Prometheus
RabbitMQ
VirtualBox
Cheat Sheet
Google Cloud Platform tips and tricks.

gcloud

Other Cheat Sheets

Install

Download the latest version: https://cloud.google.com/sdk/docs/install
1
echo "export CLOUDSDK_PYTHON=$(which python3)" >> ~/.zshrc
2
source ~/.zshrc
3
./install.sh
Copied!

Install/remove components

1
gcloud components install COMPONENT_ID
2
gcloud components remove COMPONENT_ID
Copied!

Config

Change project default Project

1
gcloud config set project my-project
Copied!
You may also set the environment variable CLOUDSDK_CORE_PROJECT.

Change project default Compute Engine Region

1
gcloud config set compute/region NAME
Copied!

Change project default Compute Engine Zone

1
gcloud config set compute/zone NAME
Copied!

Env vars

1
CLOUDSDK_COMPUTE_REGION=us-central1
2
CLOUDSDK_COMPUTE_ZONE=us-central1-a
3
CLOUDSDK_CORE_PROJECT=my-project-123456
4
CLOUDSDK_CONTAINER_CLUSTER=cluster-1
Copied!

Show current project

1
gcloud config list --format 'value(core.project)'
Copied!

List config

1
gcloud config configurations list
Copied!

Compute

SSH to VM

1
gcloud compute --project "proj-id-253611" ssh --zone us-central1-a instance-1
Copied!

Transfer files to VM

Choosing a load balancer

Delete VM
1
# Make sure you are using the correct account
2
gcloud config list
3
4
# Display instance info
5
gcloud compute instances describe instance-1 --zone=us-central1-a --project=proj-id-253611gcloud compute instances describe instance-1 --zone=us-central1-a --project=proj-id-253611
6
7
# Delete instanace and ALL DISKS
8
gcloud compute instances delete instance-1 --zone=us-central1-a --project=proj-id-253611 --delete-disks=all
Copied!

Kubernetes

Get credentials

1
gcloud container clusters get-credentials cluster-1 --zone us-central1-c --project proj-id-253611
Copied!
Deploy
1
git clone \
2
https://github.com/GoogleCloudPlatform/kubernetes-engine-samples
3
4
cd \
5
kubernetes-engine-samples/hello-app
6
7
8
docker build -t \
9
gcr.io/united-blend-253611/hello-app:v1 \
10
$PWD
11
12
gcloud docker -- push \
13
gcr.io/united-blend-253611/hello-app:v1
14
15
kubectl create deployment \
16
hello-app \
17
--image=gcr.io/united-blend-253611/hello-app:v1
18
19
kubectl expose deployment \
20
hello-app \
21
--type="LoadBalancer" --port \
22
8080
23
24
kubectl get service hello-app \
25
--watch
Copied!

Mount file system over SSH

1
# Create SSH tunnel
2
gcloud compute ssh your-instance-name --project=your-project-name -- -NL 9022:127.0.0.1:22
3
4
# Mount remote folder locally
5
sshfs -odebug,sshfs_debug,loglevel=debug,ServerAliveInterval=30,IdentityFile=~/.ssh/google_compute_engine [email protected]:/remote/folder/path /local/folder/path -p 9022
6
7
# Mount local folder remotelly
8
sshfs -odebug,sshfs_debug,loglevel=debug,ServerAliveInterval=30,IdentityFile=~/.ssh/google_compute_engine /local/folder/path [email protected]:/remote/folder/path -p 9022
Copied!
rsync
1
# Openn SSH tunnel
2
gcloud compute ssh your-instance --project=your-project -- -NL 9022:127.0.0.1:22
3
4
# Rsync from local to remote
5
rsync --progress --checksum -a -e "ssh -p 9022 -o IdentityFile=~/.ssh/google_compute_engine" /local/path [email protected]:/remote/path/
Copied!