Google Cloud CLI (gcloud)
Accounts and projects, Compute Engine, GKE credentials, Cloud Storage, logs and secrets.
Auth and projects
Log in
gcloud auth loginCredentials for local apps and Terraform (ADC)
gcloud auth application-default loginCurrent account and project
gcloud config listSwitch project
gcloud config set project <gcp_project>
Named configurations for several projectsadvanced
gcloud config configurations create <gcp_config> && gcloud config configurations activate <gcp_config>
Compute Engine
List VMs
gcloud compute instances listSSH into a VM
gcloud compute ssh <gce_instance> --zone <gcp_zone>
SSH through IAP without a public IPadvanced
gcloud compute ssh <gce_instance> --zone <gcp_zone> --tunnel-through-iap
Stop or start a VM
gcloud compute instances stop <gce_instance> --zone <gcp_zone>
GKE
List clusters
gcloud container clusters listGet kubectl credentials for a cluster
gcloud container clusters get-credentials <gke_cluster> --region <gcp_region>
Storage, logs, secrets
List buckets and objects
gcloud storage ls gs://<gcs_bucket>/
Copy files to or from a bucket
gcloud storage cp -r ./dist gs://<gcs_bucket>/
Read recent error logs
gcloud logging read 'severity>=ERROR' --limit 20 --freshness 1hRead a secret
gcloud secrets versions access latest --secret <gcp_secret>
Which APIs are enabledadvanced
gcloud services list --enabledWho has which role in the projectadvanced
gcloud projects get-iam-policy <gcp_project> --flatten='bindings[].members' --format='table(bindings.role, bindings.members)'