关于 gcloud
为使用 Google Cloud 的开发者提供 gcloud 命令行操作参考,涵盖认证、资源管理和部署示例。
主要功能
- 01配置交互式及服务账号认证
- 02列出和管理 Compute Engine 实例
- 03部署与管理 Cloud Run 服务
- 04创建并操作 Cloud Storage 存储桶
- 05格式化和筛选命令输出
适用场景
- 01从命令行部署 Cloud Run 服务
- 02管理虚拟机和 GKE 集群
- 03在 CI/CD 中配置服务账号
- 04查看或操作 Cloud Storage 资源
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ dicklesworthstone/ agent_flywheel_clawdbot_skills_and_integrations --skill gcloud安装后在 Claude Code 中输入/gcloud确认已加载。
附带文件references/IAM.mdreferences/SERVICES.md
详细介绍
GCloud CLI
**核心能力:**通过命令行管理 Google Cloud Platform 资源和服务。
快速开始
# Install
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
# Verify
gcloud version
# Check auth
gcloud auth list
# Set project
gcloud config set project PROJECT_ID
# Show current config
gcloud config list
完整提示词 — 身份验证和配置
# Login interactively
gcloud auth login
# Service account auth
gcloud auth activate-service-account --key-file=key.json
# Application default credentials
gcloud auth application-default login
# Set project
gcloud config set project PROJECT_ID
# Set region/zone
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
# Named configurations
gcloud config configurations create my-config
gcloud config configurations activate my-config
完整提示词 — Compute Engine
# List VMs
gcloud compute instances list
# Create VM
gcloud compute instances create my-vm \
--zone=us-central1-a \
--machine-type=e2-medium \
--image-family=debian-12 \
--image-project=debian-cloud
# SSH to VM
gcloud compute ssh my-vm --zone=us-central1-a
# Stop/start
gcloud compute instances stop my-vm --zone=us-central1-a
gcloud compute instances start my-vm --zone=us-central1-a
完整提示词 — Cloud Run
# List services
gcloud run services list
# Deploy from source
gcloud run deploy my-service --source . --region=us-central1
# Deploy container
gcloud run deploy my-service \
--image=gcr.io/PROJECT/IMAGE \
--region=us-central1 \
--allow-unauthenticated
# View logs
gcloud run services logs read my-service --region=us-central1
完整提示词 — Cloud Storage
# List buckets
gcloud storage buckets list
# Create bucket
gcloud storage buckets create gs://my-bucket --location=us-central1
# Upload/download
gcloud storage cp local-file.txt gs://my-bucket/
gcloud storage cp gs://my-bucket/file.txt ./
# Sync directory
gcloud storage rsync -r ./local-dir gs://my-bucket/remote-dir
基本命令
| 服务 | 列出 | 创建 | 删除 |
|---|---|---|---|
| Compute | gcloud compute instances list | gcloud compute instances create | gcloud compute instances delete |
| Cloud Run | gcloud run services list | gcloud run deploy | gcloud run services delete |
| Functions | gcloud functions list | gcloud functions deploy | gcloud functions delete |
| GKE | gcloud container clusters list | gcloud container clusters create | gcloud container clusters delete |
| Storage | gcloud storage buckets list | gcloud storage buckets create | gcloud storage rm |
输出格式
# JSON output
gcloud compute instances list --format=json
# Table with specific columns
gcloud compute instances list --format="table(name,zone,status)"
# Filter results
gcloud compute instances list --filter="status=RUNNING"
# Quiet mode (no prompts)
gcloud compute instances delete my-vm --quiet
快速参考
gcloud cheat-sheet # Built-in cheat sheet
gcloud interactive # Interactive shell
gcloud --help # General help
gcloud compute --help # Service-specific help
AGENTS.md 说明
将此内容复制到项目的 AGENTS.md 中:
### Google Cloud CLI (gcloud)
`gcloud` is installed and authenticated.
Auth:
\`\`\`bash
gcloud auth login
gcloud auth application-default login # For API libraries
\`\`\`
Project:
\`\`\`bash
gcloud config set project <PROJECT_ID>
\`\`\`
Enable APIs:
\`\`\`bash
gcloud services enable aiplatform.googleapis.com
gcloud services enable analyticsdata.googleapis.com
\`\`\`
Useful commands:
\`\`\`bash
gcloud projects list
gcloud services list --enabled
gcloud beta billing accounts list
\`\`\`
适用场景
- 为 Gemini、Vertex AI 或其他 Google 服务启用 API
- 管理账单和费用提醒
- 为 CI/CD 创建服务账号
- 将容器部署到 Cloud Run
- 管理 GKE 集群
参考资料
| 主题 | 参考资料 |
|---|---|
| 所有服务 | SERVICES.md |
| IAM 和安全 | IAM.md |
评论
支持 Markdown