Use with the Google Cloud Platform series starting at What is Google Cloud Platform?. Narrative detail lives in the chapter links below each section.
Config and auth
| Command | Purpose |
|---|---|
gcloud auth login |
User login for gcloud |
gcloud auth application-default login |
Application Default Credentials |
gcloud config set project PROJECT_ID |
Default project |
gcloud config set run/region REGION |
Default Cloud Run region |
gcloud config set artifacts/location REGION |
Default Artifact Registry location |
gcloud services enable SERVICE |
Enable an API |
See What is Google Cloud Platform?.
IAM and service accounts
| Command | Purpose |
|---|---|
gcloud projects get-iam-policy PROJECT_ID |
List project bindings |
gcloud projects add-iam-policy-binding PROJECT_ID --member=... --role=... |
Add binding |
gcloud iam service-accounts create NAME |
Create service account |
gcloud iam service-accounts add-iam-policy-binding SA --member=... --role=... |
Grant on SA |
See IAM in Google Cloud.
Cloud Storage
| Command | Purpose |
|---|---|
gcloud storage ls |
List buckets |
gcloud storage ls gs://BUCKET |
List objects |
gcloud storage cp SRC DST |
Upload or download |
gcloud storage buckets create gs://BUCKET --location=REGION |
Create bucket |
gcloud storage buckets update gs://BUCKET --versioning |
Enable versioning |
See Google Cloud Storage.
Artifact Registry
| Command | Purpose |
|---|---|
gcloud artifacts repositories create REPO --repository-format=docker --location=REGION |
Docker repo |
gcloud auth configure-docker REGION-docker.pkg.dev |
Docker credential helper |
gcloud artifacts docker images list LOCATION-docker.pkg.dev/PROJECT/REPO |
List images |
See Artifact Registry.
Cloud Run
| Command | Purpose |
|---|---|
gcloud run deploy SERVICE --image=IMAGE --region=REGION |
Deploy or update |
gcloud run services describe SERVICE --region=REGION |
Service details and URL |
gcloud run revisions list --service=SERVICE --region=REGION |
List revisions |
gcloud run services update-traffic SERVICE --to-revisions=... |
Split traffic |
See Deploying containers with Cloud Run.
Cloud Build
| Command | Purpose |
|---|---|
gcloud builds submit --config=cloudbuild.yaml . |
Run build from source |
gcloud builds list |
Recent builds |
gcloud builds log BUILD_ID |
Stream build log |
See Continuous delivery with Cloud Build.
Compute networking
| Command | Purpose |
|---|---|
gcloud compute networks create NAME --subnet-mode=custom |
Custom VPC |
gcloud compute networks subnets create NAME --network=NET --region=REGION --range=CIDR |
Subnet |
gcloud compute firewall-rules create NAME --network=NET --allow=... |
Firewall rule |
See VPC networks in Google Cloud.
Logging and monitoring
| Command | Purpose |
|---|---|
gcloud logging read 'FILTER' --limit=50 |
Query logs from CLI |
gcloud logging sinks create NAME DESTINATION --log-filter='...' |
Export logs |
gcloud monitoring uptime create NAME --host=HOST --path=/health |
Uptime check |
See Cloud Logging and Cloud Monitoring.
Cloud Shell
Browser VM with gcloud preinstalled and project auth. Same commands as a local SDK install.