InfraLab
KUBERNETES67 cmd

Kubernetes (kubectl) チート集

Pod / Deployment / Service / ConfigMap / Namespace / Node / デバッグ / context 切替の kubectl 操作。

更新日
2026-05-29
参照範囲
公式ドキュメント / man page / 主要ベンダーCLI
対象実装
主要 Linux / BSD / ネットワーク機器 CLI の一般的な実装
免責
OS とバージョン差分は実環境で確認してください。

このチートシートの使いどころ

Kubernetes チートシートは、kubectl による Pod、Deployment、Service、ConfigMap、Namespace、Node、context、デバッグ操作を日本語でまとめた一覧です。対象は現行 Kubernetes クラスタで使う標準的な kubectl 操作です。障害調査、リリース確認、権限や namespace の取り違え確認、コンテナ内での一時調査に使えます。

67 / 67

kubectl get pods

Pod一覧を表示

Example
kubectl get pods
kubectl get pods -A

全Namespaceのpodを表示

Example
kubectl get pods -A
kubectl get pods -o wide

Pod一覧を詳細情報付きで表示

Example
kubectl get pods -o wide
kubectl get pods -w

Pod一覧をリアルタイム監視

Example
kubectl get pods -w
kubectl describe pod

Podの詳細情報を表示

Example
kubectl describe pod my-pod
kubectl run

Podを作成して実行

Example
kubectl run nginx --image=nginx --port=80
kubectl delete pod

Podを削除

Example
kubectl delete pod my-pod
kubectl delete pod --force

Podを強制削除

Example
kubectl delete pod my-pod --force --grace-period=0
kubectl get pods -l

ラベルでPodをフィルタリング

Example
kubectl get pods -l app=nginx
kubectl get pod -o yaml

PodのYAML定義を表示

Example
kubectl get pod my-pod -o yaml
kubectl get deployments

Deployment一覧を表示

Example
kubectl get deployments
kubectl create deployment

Deploymentを作成

Example
kubectl create deployment nginx --image=nginx --replicas=3
kubectl apply -f

マニフェストファイルを適用

Example
kubectl apply -f deployment.yaml
kubectl delete -f

マニフェストファイルで定義されたリソースを削除

Example
kubectl delete -f deployment.yaml
kubectl scale

Deploymentのレプリカ数を変更

Example
kubectl scale deployment nginx --replicas=5
kubectl rollout status

ロールアウトの状態を確認

Example
kubectl rollout status deployment/nginx
kubectl rollout history

ロールアウト履歴を表示

Example
kubectl rollout history deployment/nginx
kubectl rollout undo

ロールバックを実行

Example
kubectl rollout undo deployment/nginx
kubectl rollout restart

Deploymentを再起動

Example
kubectl rollout restart deployment/nginx
kubectl set image

コンテナイメージを更新

Example
kubectl set image deployment/nginx nginx=nginx:1.25
kubectl autoscale

Horizontal Pod Autoscalerを設定

Example
kubectl autoscale deployment nginx --min=2 --max=10 --cpu-percent=80
kubectl get svc

Service一覧を表示

Example
kubectl get svc
kubectl expose

リソースをServiceとして公開

Example
kubectl expose deployment nginx --port=80 --type=LoadBalancer
kubectl get ingress

Ingress一覧を表示

Example
kubectl get ingress
kubectl describe svc

Serviceの詳細情報を表示

Example
kubectl describe svc my-service
kubectl delete svc

Serviceを削除

Example
kubectl delete svc my-service
kubectl get endpoints

Endpointsを表示

Example
kubectl get endpoints my-service
kubectl port-forward svc

Serviceへポートフォワード

Example
kubectl port-forward svc/my-service 8080:80
kubectl get configmaps

ConfigMap一覧を表示

Example
kubectl get configmaps
kubectl create configmap

ConfigMapを作成

Example
kubectl create configmap my-config --from-file=config.properties
kubectl get secrets

Secret一覧を表示

Example
kubectl get secrets
kubectl create secret generic

Secretを作成

Example
kubectl create secret generic my-secret --from-literal=password=mysecret
kubectl create secret tls

TLS Secretを作成

Example
kubectl create secret tls my-tls --cert=cert.pem --key=key.pem
kubectl describe configmap

ConfigMapの詳細を表示

Example
kubectl describe configmap my-config
kubectl get secret -o jsonpath

Secretの値をデコードして表示

Example
kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -d
kubectl edit configmap

ConfigMapを編集

Example
kubectl edit configmap my-config
kubectl get namespaces

Namespace一覧を表示

Example
kubectl get namespaces
kubectl create namespace

Namespaceを作成

Example
kubectl create namespace staging
kubectl delete namespace

Namespaceを削除

Example
kubectl delete namespace staging
kubectl config set-context --namespace

デフォルトNamespaceを設定

Example
kubectl config set-context --current --namespace=staging
kubectl get all -n

指定Namespaceの全リソースを表示

Example
kubectl get all -n kube-system
kubectl apply -n

指定Namespaceにマニフェストを適用

Example
kubectl apply -f app.yaml -n production
kubectl get nodes

Node一覧を表示

Example
kubectl get nodes
kubectl describe node

Nodeの詳細情報を表示

Example
kubectl describe node worker-1
kubectl top nodes

Nodeのリソース使用量を表示

Example
kubectl top nodes
kubectl top pods

Podのリソース使用量を表示

Example
kubectl top pods --sort-by=memory
kubectl cordon

Nodeをスケジュール不可に設定

Example
kubectl cordon worker-1
kubectl uncordon

Nodeをスケジュール可能に戻す

Example
kubectl uncordon worker-1
kubectl drain

Nodeからワークロードを退避

Example
kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data
kubectl taint nodes

NodeにTaintを設定

Example
kubectl taint nodes worker-1 key=value:NoSchedule
kubectl logs

Podのログを表示

Example
kubectl logs my-pod
kubectl logs -f

Podのログをリアルタイム表示

Example
kubectl logs -f my-pod
kubectl logs --previous

前回のコンテナのログを表示

Example
kubectl logs my-pod --previous
kubectl logs -c

特定のコンテナのログを表示

Example
kubectl logs my-pod -c sidecar
kubectl exec -it

Pod内で対話的にコマンドを実行

Example
kubectl exec -it my-pod -- /bin/bash
kubectl port-forward

Podへポートフォワード

Example
kubectl port-forward my-pod 8080:80
kubectl get events

クラスターイベントを表示

Example
kubectl get events --sort-by='.lastTimestamp'
kubectl debug

デバッグ用のエフェメラルコンテナを追加

Example
kubectl debug my-pod -it --image=busybox
kubectl explain

リソースのフィールドを説明

Example
kubectl explain pod.spec.containers
kubectl api-resources

利用可能なAPIリソースを表示

Example
kubectl api-resources
kubectl config get-contexts

コンテキスト一覧を表示

Example
kubectl config get-contexts
kubectl config current-context

現在のコンテキストを表示

Example
kubectl config current-context
kubectl config use-context

コンテキストを切り替え

Example
kubectl config use-context production
kubectl config set-context

コンテキストを設定

Example
kubectl config set-context my-ctx --cluster=my-cluster --user=admin
kubectl cluster-info

クラスター情報を表示

Example
kubectl cluster-info
kubectl config view

kubeconfig設定を表示

Example
kubectl config view --minify
kubectl version

クライアントとサーバーのバージョンを表示

Example
kubectl version --short
対応ツール
Related