Google Cloud CLI (gcloud) — SKILL.md
Raw skill file that agents receive when using this skill
---
name: "Google Cloud CLI (gcloud)"
description: "Skill for Google Cloud CLI (gcloud) — auto-generated from documentation"
version: "1.0.0"
author: "skynet"
category: "infrastructure"
agents: ["claude-code", "codex", "gemini"]
tags: ["gcloud-cli", "infrastructure", "auto-generated"]
---
# Google Cloud CLI (gcloud)
---
name: Google Cloud CLI (gcloud)
description: Use this skill when you need to manage Google Cloud Platform resources through the command line, including authentication, project management, compute instances, storage, and deployment operations.
metadata:
author: skynet
version: 1.0.0
category: infrastructure
---
# Google Cloud CLI (gcloud) Skills
## Authentication & Setup
### Initial Setup
```bash
# Install and initialize gcloud
gcloud init
# Login to Google Cloud
gcloud auth login
# Set application default credentials
gcloud auth application-default login
# Set active project
gcloud config set project PROJECT_ID
# List available projects
gcloud projects list
```
### Configuration Management
```bash
# Create new configuration
gcloud config configurations create CONFIG_NAME
# Switch between configurations
gcloud config configurations activate CONFIG_NAME
# Set default region/zone
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
# View current configuration
gcloud config list
```
## Compute Engine Operations
### Instance Management
```bash
# Create VM instance
gcloud compute instances create INSTANCE_NAME \
--image-family=debian-11 \
--image-project=debian-cloud \
--machine-type=e2-medium \
--zone=us-central1-a
# List instances
gcloud compute instances list
# SSH into instance
gcloud compute ssh INSTANCE_NAME --zone=us-central1-a
# Stop/start instance
gcloud compute instances stop INSTANCE_NAME --zone=us-central1-a
gcloud compute instances start INSTANCE_NAME --zone=us-central1-a
# Delete instance
gcloud compute instances delete INSTANCE_NAME --zone=us-central1-a
```
### Firewall Rules
```bash
# Create firewall rule
gcloud compute firewall-rules create allow-http \
--allow tcp:80 \
--source-ranges 0.0.0.0/0 \
--description "Allow HTTP traffic"
# List firewall rules
gcloud compute firewall-rules list
# Delete firewall rule
gcloud compute firewall-rules delete allow-http
```
## Cloud Storage Operations
### Bucket Management
```bash
# Create bucket
gsutil mb gs://BUCKET_NAME
# List buckets
gsutil ls
# Copy files to bucket
gsutil cp LOCAL_FILE gs://BUCKET_NAME/
# Copy files from bucket
gsutil cp gs://BUCKET_NAME/FILE LOCAL_PATH
# Sync directories
gsutil -m rsync -r LOCAL_DIR gs://BUCKET_NAME/
# Set bucket permissions
gsutil iam ch allUsers:objectViewer gs://BUCKET_NAME
```
## Kubernetes Engine (GKE)
### Cluster Management
```bash
# Create GKE cluster
gcloud container clusters create CLUSTER_NAME \
--zone=us-central1-a \
--num-nodes=3 \
--enable-autoscaling \
--min-nodes=1 \
--max-nodes=5
# Get cluster credentials
gcloud container clusters get-credentials CLUSTER_NAME --zone=us-central1-a
# List clusters
gcloud container clusters list
# Delete cluster
gcloud container clusters delete CLUSTER_NAME --zone=us-central1-a
```
## App Engine Deployment
### Application Deployment
```bash
# Deploy application
gcloud app deploy app.yaml
# Deploy with specific version
gcloud app deploy --version=v1 --no-promote
# View application
gcloud app browse
# View logs
gcloud app logs tail -s default
# List versions
gcloud app versions list
```
## Cloud Functions
### Function Management
```bash
# Deploy function
gcloud functions deploy FUNCTION_NAME \
--runtime=python39 \
--trigger-http \
--entry-point=main \
--source=.
# List functions
gcloud functions list
# View function logs
gcloud functions logs read FUNCTION_NAME
# Delete function
gcloud functions delete FUNCTION_NAME
```
## Decision Trees
### Choose Compute Service
```
Need to run code?
├─ Serverless, event-driven → Cloud Functions
├─ Containerized applications
│ ├─ Need orchestration → GKE
│ └─ Simple container → Cloud Run
├─ Web applications → App Engine
└─ Full VM control → Compute Engine
```
### Storage Selection
```
What type of data?
├─ Object storage (files, backups) → Cloud Storage
├─ Relational database → Cloud SQL
├─ NoSQL document → Firestore
└─ In-memory cache → Memorystore
```
## Common Workflows
### Deploy Static Website
```bash
# Create bucket with website configuration
gsutil mb gs://my-website-bucket
gsutil web set -m index.html -e 404.html gs://my-website-bucket
# Upload files
gsutil -m cp -r ./website/* gs://my-website-bucket
# Make files public
gsutil -m acl ch -r -u AllUsers:R gs://my-website-bucket/*
```
### Set up CI/CD with Cloud Build
```bash
# Submit build manually
gcloud builds submit --config=cloudbuild.yaml
# Create trigger for GitHub repo
gcloud builds triggers create github \
--repo-name=REPO_NAME \
--repo-owner=OWNER \
--branch-pattern="^main$" \
--build-config=cloudbuild.yaml
```
## Troubleshooting
### Common Errors and Fixes
**Error: "Default credentials not available"**
```bash
# Fix: Set up authentication
gcloud auth application-default login
```
**Error: "Permission denied (403)"**
```bash
# Fix: Check IAM permissions
gcloud projects get-iam-policy PROJECT_ID
# Add required roles
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:EMAIL" \
--role="roles/ROLE_NAME"
```
**Error: "Quota exceeded"**
```bash
# Check quotas
gcloud compute project-info describe --project=PROJECT_ID
# Request quota increase in Cloud Console
```
**Error: "Zone/region not found"**
```bash
# List available zones
gcloud compute zones list
# Set correct zone
gcloud config set compute/zone VALID_ZONE
```
### Debugging Commands
```bash
# Enable verbose logging
gcloud --verbosity=debug COMMAND
# Check current configuration
gcloud info
# Validate authentication
gcloud auth list
# Test connectivity
gcloud compute instances list --filter="status:RUNNING"
```
### Resource Cleanup
```bash
# Delete all stopped instances
gcloud compute instances list --filter="status:TERMINATED" --format="value(name,zone)" | \
while read name zone; do
gcloud compute instances delete $name --zone=$zone --quiet
done
# Clean up old App Engine versions
gcloud app versions list --service=default --sort-by=~version.createTime --format="value(version.id)" | \
tail -n +6 | \
xargs -I {} gcloud app versions delete {} --service=default --quiet
```
## Resource Management
### Cost Optimization
```bash
# List expensive resources
gcloud compute instances list --format="table(name,machineType,status,zone)" \
--filter="machineType:n1-highmem OR machineType:n1-highcpu"
# Schedule instance stop/start
gcloud compute instances stop INSTANCE_NAME --zone=ZONE
# Use Cloud Scheduler for automation
# Set up budget alerts
gcloud billing budgets create \
--billing-account=BILLING_ACCOUNT_ID \
--display-name="Monthly Budget" \
--budget-amount=100USD
```
curl -s https://skills.skynet.ceo/api/skills/gcloud-cli/skill.md