kubectl 基本
| コマンド | 説明 |
|---|---|
kubectl get pods | Pod一覧 |
kubectl get pods -A | 全NamespaceのPod |
kubectl get services | Service一覧 |
kubectl get deployments | Deployment一覧 |
kubectl get nodes | Node一覧 |
kubectl get all | すべてのリソース |
Pod操作
| コマンド | 説明 |
|---|---|
kubectl describe pod <name> | Pod詳細 |
kubectl logs <pod> | ログを表示 |
kubectl logs -f <pod> | ログをフォロー |
kubectl exec -it <pod> -- sh | コンテナに入る |
kubectl delete pod <name> | Podを削除 |
kubectl port-forward <pod> 8080:80 | ポートフォワード |
リソース作成・適用
| コマンド | 説明 |
|---|---|
kubectl apply -f <file.yaml> | マニフェストを適用 |
kubectl create -f <file.yaml> | リソースを作成 |
kubectl delete -f <file.yaml> | リソースを削除 |
kubectl edit <resource> <name> | リソースを編集 |
Deployment
| コマンド | 説明 |
|---|---|
kubectl scale deployment <name> --replicas=3 | スケール |
kubectl rollout status deployment/<name> | ロールアウト状態 |
kubectl rollout history deployment/<name> | ロールアウト履歴 |
kubectl rollout undo deployment/<name> | ロールバック |
Namespace
| コマンド | 説明 |
|---|---|
kubectl get namespaces | Namespace一覧 |
kubectl create namespace <name> | Namespace作成 |
kubectl config set-context --current --namespace=<ns> | デフォルトNS変更 |
デバッグ
| コマンド | 説明 |
|---|---|
kubectl describe <resource> <name> | 詳細情報 |
kubectl get events | イベント一覧 |
kubectl top pods | リソース使用量 |
kubectl top nodes | Nodeリソース使用量 |