DevOps Buzz
  • Initial page
  • About me
  • Ansible
    • Cheat Sheet
    • Dynamic inventory
  • AKS
    • Cheat Sheet
    • Autoscale
    • Backup
    • Dashboard
    • Ingress
    • Node management
    • News
    • Persistent Volumes
  • Arch Linux
    • Docker
    • Install
    • Network
    • VirtualBox guest
  • Azure
    • API
    • CLI/Powershell
    • DevOps
      • Cheat Sheet
    • Application Gateway
    • Tools
    • Sops
  • AWS
    • Cheat Sheet
    • Tools
    • Cognito with Amplify and React
  • Bash / Shell
    • Cheat Sheet
    • Tools
  • Bitbucket
    • Cheat Sheet
  • CSS
    • Cheat Sheet
  • Distros
    • Manjaro
  • Docker
    • Cheat Sheet
    • ELK
    • Ubuntu NoVNC
    • Tools
    • Known errors and solutions
  • Elasticsearch
    • Cheat Sheet
    • Tools
  • ELK
    • Cheat Sheet
  • emacs
    • Cheat sheet
  • Gatekeeper (OPA)
    • Cheat Sheet
    • Developer Quick Start
  • GCP
    • Cheat Sheet
  • General
    • Tools
    • News
  • Git
    • Cheat Sheet
    • Tools
  • Golang
    • Cheat Sheet
  • Guidelines / Standards
    • Cheat Sheet
  • i3wm
    • Cheat Sheet
  • Ipsec
    • Cheat sheet
  • Istio
    • Cheat Sheet
  • Kind
    • Cheat Sheet
  • Kops
    • Cheat Sheet
  • Kubeadm
    • Cheat Sheet
    • Change serviceSubnet CIDR
    • Setup cluster
      • Azure
      • Bare-metal
      • Vagrant + VirtualBox
    • Multi master
    • Known errors and solutions
  • Kubernetes
    • Kubectl Cheat Sheet
    • etcd Cheat Sheet
    • Tools
    • News
    • Deployments
      • Deployment examples
      • Blue/Green Deployment
      • Canary Deployment
    • Dashboard
    • ELK
    • Helm
    • Ingress
    • logz.io
    • Minikube
    • Monitoring
    • Node Management
    • Operators
    • Security
    • Volumes
    • Networking
    • kube-controller-manager
      • Node crash recovery
    • Known errors and solutions
  • Lumen
    • Cheat Sheet
  • MACOS
    • Cheat Sheet
    • Qemu
    • Zsh
  • microk8s
    • Cheat Sheet
  • MongoDB
    • Cheat Sheet
    • Tools
  • MySQL
    • Cheat Sheet
  • Network
    • Tools
    • WDS - Wireless Distribution System
    • Expose server under NAT
  • nvim
    • Cheat Sheet
  • Openvpn
    • OpenVPN server on Ubuntu 18.06
    • Stunnel
  • PHP
    • Composer
  • Prometheus
    • Tools
  • Python
    • Cheat Sheet
    • Pydantic
    • Tools / Modules
    • Virtualenv
  • RabbitMQ
    • Cheat Sheet
  • ReactJS
    • Fixes
    • For beginners
  • Ruby
    • Cheat Sheet
    • Rails
    • rvm
  • Rundeck
    • Cheat Sheet
  • Rust
    • Cheat Sheet
  • Squid
    • Setup server
    • Expose NAT server
  • SRE
    • Cheat Sheet
  • SSH
    • Passwordless auth with RSA key
    • Reverse tunnel
    • Cheat Sheet
  • SSL
    • Cheat Sheet
    • certbot
  • STACK SETUP
    • Using EKS and Gitlab CI to deploy applications
  • Terraform
    • Cheat Sheet
    • Tools
  • Tmux
    • Cheat Sheet
  • Tor
    • Cheat Sheet
  • Ubuntu
    • Cheat Sheet
  • Vagrant
    • Cheat Sheet
  • VirtualBox
    • Cheat Sheet
  • Windows
    • Windows Docker
    • Fingerprint
    • SSH Client
    • Tools
    • VirtualBox
    • WSL
Powered by GitBook
On this page
  • gcloud
  • Other Cheat Sheets
  • Install
  • Install/remove components
  • Config
  • Change project default Project
  • Change project default Compute Engine Region
  • Change project default Compute Engine Zone
  • Env vars
  • Show current project
  • List config
  • Compute
  • SSH to VM
  • Transfer files to VM
  • Choosing a load balancer
  • Kubernetes
  • Get credentials
  • Mount file system over SSH
  1. GCP

Cheat Sheet

Google Cloud Platform tips and tricks.

PreviousDeveloper Quick StartNextTools

Last updated 4 years ago

gcloud

Other Cheat Sheets

Install

Download the latest version:

echo "export CLOUDSDK_PYTHON=$(which python3)" >> ~/.zshrc
source ~/.zshrc
./install.sh

Install/remove components

gcloud components install COMPONENT_ID
gcloud components remove COMPONENT_ID

Config

Change project default Project

gcloud config set project my-project

You may also set the environment variable CLOUDSDK_CORE_PROJECT.

Change project default Compute Engine Region

gcloud config set compute/region NAME

Change project default Compute Engine Zone

gcloud config set compute/zone NAME

Env vars

CLOUDSDK_COMPUTE_REGION=us-central1
CLOUDSDK_COMPUTE_ZONE=us-central1-a
CLOUDSDK_CORE_PROJECT=my-project-123456
CLOUDSDK_CONTAINER_CLUSTER=cluster-1

Show current project

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

List config

gcloud config configurations list

Compute

SSH to VM

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

Transfer files to VM

Choosing a load balancer

Delete VM

# Make sure you are using the correct account
gcloud config list

# Display instance info
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

# Delete instanace and ALL DISKS
gcloud compute instances delete instance-1 --zone=us-central1-a --project=proj-id-253611 --delete-disks=all

Kubernetes

Get credentials

gcloud container clusters get-credentials cluster-1 --zone us-central1-c --project proj-id-253611

Deploy

git clone \
    https://github.com/GoogleCloudPlatform/kubernetes-engine-samples
    
cd \
    kubernetes-engine-samples/hello-app
    

docker build -t \
    gcr.io/united-blend-253611/hello-app:v1 \
    $PWD
    
gcloud docker -- push \
    gcr.io/united-blend-253611/hello-app:v1
    
kubectl create deployment \
    hello-app \
    --image=gcr.io/united-blend-253611/hello-app:v1
    
kubectl expose deployment \
    hello-app \
    --type="LoadBalancer" --port \
    8080
    
kubectl get service hello-app \
    --watch

Mount file system over SSH

# Create SSH tunnel
gcloud compute ssh your-instance-name --project=your-project-name -- -NL 9022:127.0.0.1:22

# Mount remote folder locally
sshfs -odebug,sshfs_debug,loglevel=debug,ServerAliveInterval=30,IdentityFile=~/.ssh/google_compute_engine your-username@localhost:/remote/folder/path /local/folder/path -p 9022

# Mount local folder remotelly
sshfs -odebug,sshfs_debug,loglevel=debug,ServerAliveInterval=30,IdentityFile=~/.ssh/google_compute_engine /local/folder/path your-username@localhost:/remote/folder/path -p 9022

rsync

# Openn SSH tunnel
gcloud compute ssh your-instance --project=your-project -- -NL 9022:127.0.0.1:22

# Rsync from local to remote
rsync --progress --checksum -a -e "ssh -p 9022 -o IdentityFile=~/.ssh/google_compute_engine" /local/path your-user@localhost:/remote/path/

https://cloud.google.com/sdk/gcloud/reference
http://cheat.sh/gcloud
https://gist.github.com/pydevops/cffbd3c694d599c6ca18342d3625af97#file-gcloud_cheat_sheet-md
https://cloud.google.com/sdk/docs/install
https://cloud.google.com/compute/docs/instances/transfer-files/
https://cloud.google.com/load-balancing/docs/choosing-load-balancer
https://cloud.google.com/load-balancing/docs/https/setting-up-https