GCP Cheatsheet

Pre-req

Auth with gcloud cli

gcloud auth login --brief --activate		# Autenticarse con GCP
gcloud config set account `ACCOUNT`

gcloud auth revoke test@gmail.com
gcloud auth list
gcloud config list project # list projects

# auth to gcloud with service account
gcloud auth activate-service-account --project=someproject --key-file=gcpcmdlineuser.json
gcloud info

Projects

gcloud projects list
gcloud config set project $MYPROJECTID

Usage of gsutil

gsutil ls

GCP y repositorios

gcloud alpha source repos create default

GCP y Docker

gcloud docker -- push grc.io/$PROJECT_ID/$IMAGE:$TAG	# Subir una imagen (OLD WAY)
gcloud auth configure-docker	# configurar docker-cli para subir imagenes a GRC

Desplegar un GKE

gcloud container clusters create $CLUSTER_NAME
gcloud container clusters get-credentials $CLUSTER_NAME

gcloud beta** container --project "dummy-233720" clusters create "dummy-cluster" --zone "us-west1-a" --username "admin" --cluster-version "1.11.7-gke.4" --machine-type "g1-small" --image-type "COS" --disk-type "pd-standard" --disk-size "100" --scopes "https://www.googleapis.com/auth/devstorage.read\_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "2" --enable-cloud-logging --enable-cloud-monitoring --no-enable-ip-alias --network "projects/dummy-233720/global/networks/default" --subnetwork "projects/dummy-233720/regions/us-west1/subnetworks/default" --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair

gcloud container clusters create bootcamp --num-nodes 5 --scopes "https://www.googleapis.com/auth/projecthosting,storage-rw"

gcloud container clusters create my-cluster --scopes "https://www.googleapis.com/auth/projecthosting,storage-rw"

gcloud container clusters create jenkins-cd \
--num-nodes 2 \
--machine-type n1-standard-2 \
--scopes "https://www.googleapis.com/auth/projecthosting,cloud-platform"

Comandos GKE

export GC_PROJECT=dummy
export GC_ZONE=us-west1-a
export GC_KUBENAME=dummy

gcloud config set project $GC_PROJECT
gcloud config set compute/zone $GC_ZONE
gcloud config set container/cluster $GC_KUBENAME

gcloud container clusters create $GC_KUBENAME \
--zone $GC_ZONE \
--enable-cloud-logging \
--enable-cloud-monitoring \
--machine-type n1-standard-1 \
--num-nodes 3

gcloud container clusters get-credentials $GC_KUBENAME # Configurar kubeconfig para $GC_KUBENAME (cluster k8s)

gcloud config set project $GC_PROJECT
gcloud config set compute/zone $GC_ZONE
gcloud config set container/cluster $GC_KUBENAME

kubectl config get-contexts # Para verificar el contexto actual

gcloud config get-value project
gcloud config get-value compute/zone
gcloud config get-value container/cluster

gcloud container clusters get-credentials $GC_KUBENAME --zone $GC_ZONE --project $GC_PROJECT

# quick verification
gcloud container clusters list
gcloud container clusters get-credentials $CLUSTER_NAME

# Remove cluster
gcloud container clusters delete $CLUSTERNAME

Networking

gcloud compute firewall-rules create $rule_name \
  --allow tcp:9090 \
  --source-tags=${list-of-your-instances-names} \
  --source-ranges=0.0.0.0/0 \
  --description="<your-description-here>"

# List all firweall rules
gcloud compute firewall-rules list
gcloud compute firewall-rules list --uri
gcloud compute firewall-rules list --sort-by=NETWORK

Computing

# list of instances
gcloud compute instances list

# create instance
gcloud compute instances create nxb-vpn nxb-app1 --zone=us-west1-a

# ssh into server
gcloud compute ssh nxb-vpn --zone=us-west1-a

References