mcpField
G
gcp

gcp

github.com/thelobbiクラウド・DevOps2188 回インストール3 日前に更新
リポジトリ

gcp について

gcpは、Google Cloud Platformの操作に関するコマンドライン、Python SDK、Terraformのガイドを提供するスキルです。GKE、Cloud Run、Cloud Storage、BigQuery、Pub/Subの管理を対象としています。

主な機能

  1. 01gcloudの設定と認証
  2. 02GKEクラスター操作
  3. 03Cloud Runサービスのデプロイ
  4. 04Cloud Storageのファイル操作
  5. 05BigQueryのクエリとデータ転送
  6. 06Pub/Subのメッセージ例

活用シーン

  1. 01GKEクラスターの管理
  2. 02Cloud Runへのサービスデプロイ
  3. 03Cloud Storageを使ったファイル転送
  4. 04BigQueryのクエリやPub/Subメッセージの処理

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/thelobbi/claude --skill gcp

インストール後、Claude Code で/gcpを入力して読み込まれたか確認します。

詳細

GCP スキル

Golden Armada AI Agent Fleet Platform 向けに、Google Cloud Platform の包括的な機能を提供します。

このスキルを使用する場面

以下の作業を行うときに、このスキルを有効にします。

  • GKE クラスターの管理
  • Cloud Run のデプロイ
  • Cloud Storage の操作
  • BigQuery によるデータ分析
  • Pub/Sub によるメッセージング

gcloud CLI クイックリファレンス

設定

```bash

初期化

gcloud init

認証

gcloud auth login gcloud auth application-default login

プロジェクトを設定

gcloud config set project PROJECT_ID

設定を確認

gcloud config list gcloud info ```

GKE(Google Kubernetes Engine)

```bash

クラスターを作成

gcloud container clusters create golden-armada-cluster
--zone us-central1-a
--num-nodes 3
--machine-type e2-standard-4
--enable-autoscaling --min-nodes 1 --max-nodes 10

認証情報を取得

gcloud container clusters get-credentials golden-armada-cluster --zone us-central1-a

クラスターを一覧表示

gcloud container clusters list

クラスターのサイズを変更

gcloud container clusters resize golden-armada-cluster --num-nodes 5 --zone us-central1-a

クラスターを削除

gcloud container clusters delete golden-armada-cluster --zone us-central1-a ```

Cloud Run

```bash

サービスをデプロイ

gcloud run deploy golden-armada-api
--image gcr.io/PROJECT_ID/agent:latest
--platform managed
--region us-central1
--allow-unauthenticated
--set-env-vars "ENV=production"

サービスを一覧表示

gcloud run services list

サービス URL を取得

gcloud run services describe golden-armada-api --platform managed --region us-central1 --format 'value(status.url)'

トラフィックを更新

gcloud run services update-traffic golden-armada-api
--to-revisions REVISION=100 ```

Cloud Storage

```bash

バケットを作成

gsutil mb -l us-central1 gs://golden-armada-data

ファイルをコピー

gsutil cp local-file.txt gs://bucket-name/ gsutil cp gs://bucket-name/file.txt . gsutil -m cp -r ./local-dir gs://bucket-name/

一覧表示

gsutil ls gs://bucket-name/

同期

gsutil rsync -r ./local-dir gs://bucket-name/dir/

権限を設定

gsutil iam ch allUsers:objectViewer gs://bucket-name ```

BigQuery

```bash

データセットを作成

bq mk --dataset PROJECT_ID:agents_dataset

テーブルを作成

bq mk --table agents_dataset.agent_logs schema.json

クエリを実行

bq query --use_legacy_sql=false
'SELECT * FROM project.dataset.table LIMIT 10'

データを読み込む

bq load --source_format=NEWLINE_DELIMITED_JSON
agents_dataset.logs gs://bucket/logs/*.json

エクスポート

bq extract --destination_format NEWLINE_DELIMITED_JSON
agents_dataset.logs gs://bucket/export/logs-*.json ```

Pub/Sub

```bash

トピックを作成

gcloud pubsub topics create agent-events

サブスクリプションを作成

gcloud pubsub subscriptions create agent-events-sub
--topic agent-events

メッセージをパブリッシュ

gcloud pubsub topics publish agent-events
--message '{"event": "agent_started", "agent_id": "123"}'

メッセージを取得

gcloud pubsub subscriptions pull agent-events-sub --auto-ack ```

Python SDK

```python from google.cloud import storage, bigquery, pubsub_v1

Cloud Storage

storage_client = storage.Client() bucket = storage_client.bucket('golden-armada-data')

アップロード

blob = bucket.blob('agents/config.json') blob.upload_from_string(json.dumps(config))

ダウンロード

blob = bucket.blob('agents/config.json') content = blob.download_as_string()

BigQuery

bq_client = bigquery.Client()

query = """ SELECT agent_id, COUNT(*) as task_count FROM project.dataset.tasks GROUP BY agent_id ORDER BY task_count DESC """ results = bq_client.query(query) for row in results: print(f"{row.agent_id}: {row.task_count}")

行を挿入

table_ref = bq_client.dataset('agents_dataset').table('logs') errors = bq_client.insert_rows_json(table_ref, rows)

Pub/Sub Publisher

publisher = pubsub_v1.PublisherClient() topic_path = publisher.topic_path('project-id', 'agent-events')

future = publisher.publish( topic_path, json.dumps({"event": "task_completed"}).encode(), agent_id="123" ) message_id = future.result()

Pub/Sub Subscriber

subscriber = pubsub_v1.SubscriberClient() subscription_path = subscriber.subscription_path('project-id', 'agent-events-sub')

def callback(message): print(f"Received: {message.data}") message.ack()

streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback) ```

Terraform GCP Resources

```hcl provider "google" { project = var.project_id region = var.region }

GKE Cluster

resource "google_container_cluster" "primary" { name = "golden-armada-cluster" location = var.zone

remove_default_node_pool = true initial_node_count = 1

network = google_compute_network.vpc.name subnetwork = google_compute_subnetwork.subnet.name }

resource "google_container_node_pool" "primary_nodes" { name = "primary-node-pool" location = var.zone cluster = google_container_cluster.primary.name node_count = 3

node_config { machine_type = "e2-standard-4" oauth_scopes = [ "https://www.googleapis.com/auth/cloud-platform" ] }

autoscaling { min_node_count = 1 max_node_count = 10 } }

Cloud Run Service

resource "google_cloud_run_service" "agent_api" { name = "golden-armada-api" location = var.region

template { spec { containers { image = "gcr.io/${var.project_id}/agent:latest" env { name = "ENV" value = "production" } } } }

traffic { percent = 100 latest_revision = true } }

Cloud Storage Bucket

resource "google_storage_bucket" "data" { name = "golden-armada-data" location = var.region

uniform_bucket_level_access = true

lifecycle_rule { condition { age = 30 } action { type = "Delete" } } } ```

コメント