kubernetes-flux について
Flux と kubectl で Kubernetes クラスターを管理するエージェント向けのスキルです。GitOps の初期設定、状態確認、リソースの調査や操作を扱い、危険な操作の確認と Secret 値のマスキングも案内します。
主な機能
- 01Flux による GitOps の初期設定と同期
- 02クラスターリソースとロールアウト状態の確認
- 03Pod、サービス、イベントの調査
- 04スケーリング、ロールバック、ポート転送
- 05危険な操作の確認と Secret 値のマスキング
活用シーン
- 01障害のある Pod やコンテナの調査
- 02デプロイのロールアウトとロールバックの監視
- 03サービスネットワークやクラスターイベントの診断
- 04Flux でリポジトリ設定を同期
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ oimiragieo/ agent-studio --skill kubernetes-fluxインストール後、Claude Code で/kubernetes-fluxを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
commands/kubernetes-flux.mdhooks/post-execute.cjspre-execute.cjsreferences/research-requirements.mdrules/kubernetes-flux.mdschemas/input.schema.jsonoutput.schema.jsonscripts/main.cjstemplates/implementation-template.md詳細
Kubernetes Flux スキル
インストール
このスキルは Flux CLI を呼び出します。次の方法でインストールしてください。
- macOS/Linux(Homebrew):
brew install fluxcd/tap/flux - macOS/Linux(スクリプト):
curl -s https://fluxcd.io/install.sh | sudo bash - Windows(winget):
winget install -e --id FluxCD.Flux - Windows(Chocolatey):
choco install flux - カスタムディレクトリ:
curl -s https://fluxcd.io/install.sh | bash -s ~/.local/bin
flux --version で確認してください。必要に応じて、flux bootstrap を使用してコントローラーをデプロイします。
チートシートとベストプラクティス
ブートストラップ: flux bootstrap git --url=ssh://git@host/repo.git --path=clusters/my-cluster。必要に応じて --branch、--interval、--private-key-file、または --token-auth を使用します。
ステータス: flux check — コントローラー/CRD;flux get all -A — すべてのリソース;flux get kustomizations;flux tree kustomization <name> — 管理対象オブジェクト。
活用のヒント: flux get sources git と flux get kustomizations を使用して同期状態を確認します。必要に応じてリコンサイルします:flux reconcile kustomization <name> --with-source。インストールスクリプトでは FLUX_VERSION を指定してバージョンを固定します。GitOps でアプリのマニフェストを管理する場合は、Helm より Git を優先してください。
認定資格とトレーニング
Kubernetes: CKA / CKAD(Linux Foundation)。Flux: Flux による GitOps(LFS269)。スキルデータ: ブートストラップ、リコンサイル、ステータス(flux check、flux get all)、ツリー;GitOps ワークフロー。
フックとワークフロー
推奨フック: 適用前:flux check。プッシュ後(Flux が使用する Git リポジトリへのプッシュ後):必要に応じてリコンサイルをトリガーします。GitOps クラスターでは devops と併用してください(常時)。
ワークフロー: devops と併用してください(常時)。フロー:ブートストラップまたはリコンサイル;flux get all、flux tree kustomization を使用してデバッグします。gitops-workflow スキルとエンタープライズワークフローを参照してください。
概要
このスキルは kubectl を通じて包括的な Kubernetes クラスター管理を提供し、AI エージェントが Kubernetes リソースを調査、トラブルシューティング、管理できるようにします。
使用するタイミング
- アプリケーションのポッドやコンテナーのデバッグ
- デプロイのロールアウトとステータスの監視
- サービスのネットワークとエンドポイントの分析
- クラスターのイベントやエラーの調査
- パフォーマンスの問題のトラブルシューティング
- アプリケーションのスケーリング管理
- ローカル開発用のポートフォワーディング
要件
- kubectl がインストールされ、設定されていること
- 有効な KUBECONFIG ファイルまたはデフォルトのコンテキスト
- クラスターへのアクセス認証情報
- 適切な RBAC 権限
クイックリファレンス
# Get pods in current namespace
kubectl get pods
# Get pods in specific namespace
kubectl get pods -n production
# Get pods with labels
kubectl get pods -l app=web -n production
# Describe a pod
kubectl describe pod my-app-123 -n default
# Get pod logs
kubectl logs my-app-123 -n default
# Get logs with tail
kubectl logs my-app-123 -n default --tail=100
# Get logs since time
kubectl logs my-app-123 -n default --since=1h
# List recent events
kubectl get events -n default --sort-by='.lastTimestamp' | tail -20
# Watch events in real-time
kubectl get events -n default -w
リソースの検出
ポッド
# List all pods
kubectl get pods -n <namespace>
# List pods with wide output
kubectl get pods -n <namespace> -o wide
# List pods across all namespaces
kubectl get pods -A
# Filter by label
kubectl get pods -l app=nginx -n <namespace>
デプロイ
# List deployments
kubectl get deployments -n <namespace>
# Get deployment details
kubectl describe deployment <name> -n <namespace>
# Check rollout status
kubectl rollout status deployment/<name> -n <namespace>
サービス
# List services
kubectl get svc -n <namespace>
# Describe service
kubectl describe svc <name> -n <namespace>
# Get endpoints
kubectl get endpoints <name> -n <namespace>
ConfigMap と Secret
# List ConfigMaps
kubectl get configmaps -n <namespace>
# Describe ConfigMap
kubectl describe configmap <name> -n <namespace>
# Get ConfigMap data
kubectl get configmap <name> -n <namespace> -o yaml
# List Secrets (names only)
kubectl get secrets -n <namespace>
# Describe Secret (values masked)
kubectl describe secret <name> -n <namespace>
名前空間
# List namespaces
kubectl get namespaces
# Get namespace details
kubectl describe namespace <name>
トラブルシューティング
ポッドのデバッグ
# Describe pod for events and conditions
kubectl describe pod <name> -n <namespace>
# Get pod logs
kubectl logs <pod-name> -n <namespace>
# Get logs from specific container
kubectl logs <pod-name> -c <container-name> -n <namespace>
# Get previous container logs (after crash)
kubectl logs <pod-name> -n <namespace> --previous
# Exec into pod
kubectl exec -it <pod-name> -n <namespace> -- /bin/sh
# Run command in pod
kubectl exec <pod-name> -n <namespace> -- ls -la /app
イベント
# List events sorted by time
kubectl get events -n <namespace> --sort-by='.lastTimestamp'
# Filter warning events
kubectl get events -n <namespace> --field-selector type=Warning
# Watch events live
kubectl get events -n <namespace> -w
管理操作
スケーリング
# Scale deployment
kubectl scale deployment <name> --replicas=5 -n <namespace>
# Autoscale deployment
kubectl autoscale deployment <name> --min=2 --max=10 --cpu-percent=80 -n <namespace>
ロールアウト
# Check rollout status
kubectl rollout status deployment/<name> -n <namespace>
# View rollout history
kubectl rollout history deployment/<name> -n <namespace>
# Rollback to previous version
kubectl rollout undo deployment/<name> -n <namespace>
# Rollback to specific revision
kubectl rollout undo deployment/<name> --to-revision=2 -n <namespace>
ポートフォワーディング
# Forward local port to pod
kubectl port-forward <pod-name> 8080:80 -n <namespace>
# Forward to service
kubectl port-forward svc/<service-name> 8080:80 -n <namespace>
コンテキスト管理
# Get current context
kubectl config current-context
# List all contexts
kubectl config get-contexts
# Switch context
kubectl config use-context <context-name>
# Set default namespace
kubectl config set-context --current --namespace=<namespace>
一般的なワークフロー
失敗しているポッドのトラブルシューティング
# 1. Find the problematic pod
kubectl get pods -n production
# 2. Describe for events
kubectl describe pod <pod-name> -n production
# 3. Check events
kubectl get events -n production --sort-by='.lastTimestamp' | tail -20
# 4. Get logs
kubectl logs <pod-name> -n production --tail=200
デプロイのロールアウトを監視する
# 1. Check deployment status
kubectl get deployments -n production
# 2. Watch rollout
kubectl rollout status deployment/<name> -n production
# 3. Watch pods
kubectl get pods -l app=<app-name> -n production -w
サービス接続をデバッグする
# 1. Check service
kubectl describe svc <name> -n <namespace>
# 2. Check endpoints
kubectl get endpoints <name> -n <namespace>
# 3. Check backing pods
kubectl get pods -l <service-selector> -n <namespace>
# 4. Port forward for testing
kubectl port-forward svc/<name> 8080:80 -n <namespace>
安全機能
ブロックされる操作
以下の操作は危険なため、確認が必要です。
kubectl deleteコマンド- 破壊的な exec コマンド(rm、dd、mkfs)
- 本番環境でレプリカ数を 0 にスケーリングする操作
マスクされる出力
Secret の値は常にマスクされます。メタデータのみが表示されます。
エラー処理
| エラー | 原因 | 対処法 |
|---|---|---|
kubectl not found | インストールされていない | kubectl をインストールする |
Unable to connect | クラスターに到達できない | ネットワーク/VPN を確認する |
Forbidden | RBAC 権限 | 権限を申請する |
NotFound | リソースが見つからない | 名前/名前空間を確認する |
context deadline exceeded | タイムアウト | クラスターの状態を確認する |
関連情報
- kubectl のドキュメント:https://kubernetes.io/docs/reference/kubectl/
- Kubernetes API:https://kubernetes.io/docs/reference/kubernetes-api/
メモリプロトコル(必須)
開始前:
cat .claude/context/memory/learnings.md
完了後: 新たに見つかったパターンや例外を記録してください。
中断を想定してください。コンテキストがリセットされる可能性があります。メモリに記録されていなければ、実行されていないものとして扱ってください。