Cloud

gcloud CLI

Google Cloud gcloud CLI commands for infrastructure management.

37 commands
Windows MacOS Linux
#google-cloud #infrastructure

Configuration

Initialize and configure gcloud
gcloud init
Authenticate with Google Cloud
gcloud auth login
Set the active project
gcloud config set project my-project
Set default region
gcloud config set compute/region us-central1
Set default zone
gcloud config set compute/zone us-central1-a
List current configuration
gcloud config list
List all accessible projects
gcloud projects list

Compute

List all VM instances
gcloud compute instances list
Create VM
gcloud compute instances create my-vm --machine-type=e2-medium --image-family=debian-12 --image-project=debian-cloud
Start a stopped VM
gcloud compute instances start my-vm
Stop a running VM
gcloud compute instances stop my-vm
Delete a VM instance
gcloud compute instances delete my-vm
SSH into a VM instance
gcloud compute ssh my-vm

Storage

Create a storage bucket
gcloud storage buckets create gs://my-bucket
Delete a storage bucket
gcloud storage buckets delete gs://my-bucket
Upload file to bucket
gcloud storage cp file.txt gs://my-bucket/
Download file from bucket
gcloud storage cp gs://my-bucket/file.txt .
List objects in bucket
gcloud storage ls gs://my-bucket
Delete an object
gcloud storage rm gs://my-bucket/file.txt

IAM

List service accounts
gcloud iam service-accounts list
Create service account
gcloud iam service-accounts create my-sa --display-name="My SA"
Grant role
gcloud projects add-iam-policy-binding my-project --member=serviceAccount:[email protected] --role=roles/editor
Create SA key
gcloud iam service-accounts keys create key.json [email protected]

Kubernetes Engine

List GKE clusters
gcloud container clusters list
Create a GKE cluster
gcloud container clusters create my-cluster --num-nodes=3
Configure kubectl for cluster
gcloud container clusters get-credentials my-cluster
Resize cluster node pool
gcloud container clusters resize my-cluster --num-nodes=5
Delete a GKE cluster
gcloud container clusters delete my-cluster

Networking

List VPC networks
gcloud compute networks list
Create VPC network
gcloud compute networks create my-vpc --subnet-mode=auto
List firewall rules
gcloud compute firewall-rules list
Create firewall rule
gcloud compute firewall-rules create allow-http --allow tcp:80 --network my-vpc
List static IP addresses
gcloud compute addresses list
Reserve static IP
gcloud compute addresses create my-ip --region=us-central1

Quick Commands

List all VM instances in the project
gcloud compute instances list
Set the active Google Cloud project
gcloud config set project <project-id>
Configure kubectl to use a GKE cluster
gcloud container clusters get-credentials <cluster>