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 podsPod一覧を表示
kubectl get podskubectl get pods -A全Namespaceのpodを表示
kubectl get pods -Akubectl get pods -o widePod一覧を詳細情報付きで表示
kubectl get pods -o widekubectl get pods -wPod一覧をリアルタイム監視
kubectl get pods -wkubectl describe podPodの詳細情報を表示
kubectl describe pod my-podkubectl runPodを作成して実行
kubectl run nginx --image=nginx --port=80kubectl delete podPodを削除
kubectl delete pod my-podkubectl delete pod --forcePodを強制削除
kubectl delete pod my-pod --force --grace-period=0kubectl get pods -lラベルでPodをフィルタリング
kubectl get pods -l app=nginxkubectl get pod -o yamlPodのYAML定義を表示
kubectl get pod my-pod -o yamlkubectl get deploymentsDeployment一覧を表示
kubectl get deploymentskubectl create deploymentDeploymentを作成
kubectl create deployment nginx --image=nginx --replicas=3kubectl apply -fマニフェストファイルを適用
kubectl apply -f deployment.yamlkubectl delete -fマニフェストファイルで定義されたリソースを削除
kubectl delete -f deployment.yamlkubectl scaleDeploymentのレプリカ数を変更
kubectl scale deployment nginx --replicas=5kubectl rollout statusロールアウトの状態を確認
kubectl rollout status deployment/nginxkubectl rollout historyロールアウト履歴を表示
kubectl rollout history deployment/nginxkubectl rollout undoロールバックを実行
kubectl rollout undo deployment/nginxkubectl rollout restartDeploymentを再起動
kubectl rollout restart deployment/nginxkubectl set imageコンテナイメージを更新
kubectl set image deployment/nginx nginx=nginx:1.25kubectl autoscaleHorizontal Pod Autoscalerを設定
kubectl autoscale deployment nginx --min=2 --max=10 --cpu-percent=80kubectl get svcService一覧を表示
kubectl get svckubectl exposeリソースをServiceとして公開
kubectl expose deployment nginx --port=80 --type=LoadBalancerkubectl get ingressIngress一覧を表示
kubectl get ingresskubectl describe svcServiceの詳細情報を表示
kubectl describe svc my-servicekubectl delete svcServiceを削除
kubectl delete svc my-servicekubectl get endpointsEndpointsを表示
kubectl get endpoints my-servicekubectl port-forward svcServiceへポートフォワード
kubectl port-forward svc/my-service 8080:80kubectl get configmapsConfigMap一覧を表示
kubectl get configmapskubectl create configmapConfigMapを作成
kubectl create configmap my-config --from-file=config.propertieskubectl get secretsSecret一覧を表示
kubectl get secretskubectl create secret genericSecretを作成
kubectl create secret generic my-secret --from-literal=password=mysecretkubectl create secret tlsTLS Secretを作成
kubectl create secret tls my-tls --cert=cert.pem --key=key.pemkubectl describe configmapConfigMapの詳細を表示
kubectl describe configmap my-configkubectl get secret -o jsonpathSecretの値をデコードして表示
kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -dkubectl edit configmapConfigMapを編集
kubectl edit configmap my-configkubectl get namespacesNamespace一覧を表示
kubectl get namespaceskubectl create namespaceNamespaceを作成
kubectl create namespace stagingkubectl delete namespaceNamespaceを削除
kubectl delete namespace stagingkubectl config set-context --namespaceデフォルトNamespaceを設定
kubectl config set-context --current --namespace=stagingkubectl get all -n指定Namespaceの全リソースを表示
kubectl get all -n kube-systemkubectl apply -n指定Namespaceにマニフェストを適用
kubectl apply -f app.yaml -n productionkubectl get nodesNode一覧を表示
kubectl get nodeskubectl describe nodeNodeの詳細情報を表示
kubectl describe node worker-1kubectl top nodesNodeのリソース使用量を表示
kubectl top nodeskubectl top podsPodのリソース使用量を表示
kubectl top pods --sort-by=memorykubectl cordonNodeをスケジュール不可に設定
kubectl cordon worker-1kubectl uncordonNodeをスケジュール可能に戻す
kubectl uncordon worker-1kubectl drainNodeからワークロードを退避
kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-datakubectl taint nodesNodeにTaintを設定
kubectl taint nodes worker-1 key=value:NoSchedulekubectl logsPodのログを表示
kubectl logs my-podkubectl logs -fPodのログをリアルタイム表示
kubectl logs -f my-podkubectl logs --previous前回のコンテナのログを表示
kubectl logs my-pod --previouskubectl logs -c特定のコンテナのログを表示
kubectl logs my-pod -c sidecarkubectl exec -itPod内で対話的にコマンドを実行
kubectl exec -it my-pod -- /bin/bashkubectl port-forwardPodへポートフォワード
kubectl port-forward my-pod 8080:80kubectl get eventsクラスターイベントを表示
kubectl get events --sort-by='.lastTimestamp'kubectl debugデバッグ用のエフェメラルコンテナを追加
kubectl debug my-pod -it --image=busyboxkubectl explainリソースのフィールドを説明
kubectl explain pod.spec.containerskubectl api-resources利用可能なAPIリソースを表示
kubectl api-resourceskubectl config get-contextsコンテキスト一覧を表示
kubectl config get-contextskubectl config current-context現在のコンテキストを表示
kubectl config current-contextkubectl config use-contextコンテキストを切り替え
kubectl config use-context productionkubectl config set-contextコンテキストを設定
kubectl config set-context my-ctx --cluster=my-cluster --user=adminkubectl cluster-infoクラスター情報を表示
kubectl cluster-infokubectl config viewkubeconfig設定を表示
kubectl config view --minifykubectl versionクライアントとサーバーのバージョンを表示
kubectl version --short| Command | Description | Example | Copy |
|---|---|---|---|
kubectl get pods | Pod一覧を表示 | kubectl get pods | |
kubectl get pods -A | 全Namespaceのpodを表示 | kubectl get pods -A | |
kubectl get pods -o wide | Pod一覧を詳細情報付きで表示 | kubectl get pods -o wide | |
kubectl get pods -w | Pod一覧をリアルタイム監視 | kubectl get pods -w | |
kubectl describe pod | Podの詳細情報を表示 | kubectl describe pod my-pod | |
kubectl run | Podを作成して実行 | kubectl run nginx --image=nginx --port=80 | |
kubectl delete pod | Podを削除 | kubectl delete pod my-pod | |
kubectl delete pod --force | Podを強制削除 | kubectl delete pod my-pod --force --grace-period=0 | |
kubectl get pods -l | ラベルでPodをフィルタリング | kubectl get pods -l app=nginx | |
kubectl get pod -o yaml | PodのYAML定義を表示 | kubectl get pod my-pod -o yaml | |
kubectl get deployments | Deployment一覧を表示 | kubectl get deployments | |
kubectl create deployment | Deploymentを作成 | kubectl create deployment nginx --image=nginx --replicas=3 | |
kubectl apply -f | マニフェストファイルを適用 | kubectl apply -f deployment.yaml | |
kubectl delete -f | マニフェストファイルで定義されたリソースを削除 | kubectl delete -f deployment.yaml | |
kubectl scale | Deploymentのレプリカ数を変更 | kubectl scale deployment nginx --replicas=5 | |
kubectl rollout status | ロールアウトの状態を確認 | kubectl rollout status deployment/nginx | |
kubectl rollout history | ロールアウト履歴を表示 | kubectl rollout history deployment/nginx | |
kubectl rollout undo | ロールバックを実行 | kubectl rollout undo deployment/nginx | |
kubectl rollout restart | Deploymentを再起動 | kubectl rollout restart deployment/nginx | |
kubectl set image | コンテナイメージを更新 | kubectl set image deployment/nginx nginx=nginx:1.25 | |
kubectl autoscale | Horizontal Pod Autoscalerを設定 | kubectl autoscale deployment nginx --min=2 --max=10 --cpu-percent=80 | |
kubectl get svc | Service一覧を表示 | kubectl get svc | |
kubectl expose | リソースをServiceとして公開 | kubectl expose deployment nginx --port=80 --type=LoadBalancer | |
kubectl get ingress | Ingress一覧を表示 | kubectl get ingress | |
kubectl describe svc | Serviceの詳細情報を表示 | kubectl describe svc my-service | |
kubectl delete svc | Serviceを削除 | kubectl delete svc my-service | |
kubectl get endpoints | Endpointsを表示 | kubectl get endpoints my-service | |
kubectl port-forward svc | Serviceへポートフォワード | kubectl port-forward svc/my-service 8080:80 | |
kubectl get configmaps | ConfigMap一覧を表示 | kubectl get configmaps | |
kubectl create configmap | ConfigMapを作成 | kubectl create configmap my-config --from-file=config.properties | |
kubectl get secrets | Secret一覧を表示 | kubectl get secrets | |
kubectl create secret generic | Secretを作成 | kubectl create secret generic my-secret --from-literal=password=mysecret | |
kubectl create secret tls | TLS Secretを作成 | kubectl create secret tls my-tls --cert=cert.pem --key=key.pem | |
kubectl describe configmap | ConfigMapの詳細を表示 | kubectl describe configmap my-config | |
kubectl get secret -o jsonpath | Secretの値をデコードして表示 | kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -d | |
kubectl edit configmap | ConfigMapを編集 | kubectl edit configmap my-config | |
kubectl get namespaces | Namespace一覧を表示 | kubectl get namespaces | |
kubectl create namespace | Namespaceを作成 | kubectl create namespace staging | |
kubectl delete namespace | Namespaceを削除 | kubectl delete namespace staging | |
kubectl config set-context --namespace | デフォルトNamespaceを設定 | kubectl config set-context --current --namespace=staging | |
kubectl get all -n | 指定Namespaceの全リソースを表示 | kubectl get all -n kube-system | |
kubectl apply -n | 指定Namespaceにマニフェストを適用 | kubectl apply -f app.yaml -n production | |
kubectl get nodes | Node一覧を表示 | kubectl get nodes | |
kubectl describe node | Nodeの詳細情報を表示 | kubectl describe node worker-1 | |
kubectl top nodes | Nodeのリソース使用量を表示 | kubectl top nodes | |
kubectl top pods | Podのリソース使用量を表示 | kubectl top pods --sort-by=memory | |
kubectl cordon | Nodeをスケジュール不可に設定 | kubectl cordon worker-1 | |
kubectl uncordon | Nodeをスケジュール可能に戻す | kubectl uncordon worker-1 | |
kubectl drain | Nodeからワークロードを退避 | kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data | |
kubectl taint nodes | NodeにTaintを設定 | kubectl taint nodes worker-1 key=value:NoSchedule | |
kubectl logs | Podのログを表示 | kubectl logs my-pod | |
kubectl logs -f | Podのログをリアルタイム表示 | kubectl logs -f my-pod | |
kubectl logs --previous | 前回のコンテナのログを表示 | kubectl logs my-pod --previous | |
kubectl logs -c | 特定のコンテナのログを表示 | kubectl logs my-pod -c sidecar | |
kubectl exec -it | Pod内で対話的にコマンドを実行 | kubectl exec -it my-pod -- /bin/bash | |
kubectl port-forward | Podへポートフォワード | kubectl port-forward my-pod 8080:80 | |
kubectl get events | クラスターイベントを表示 | kubectl get events --sort-by='.lastTimestamp' | |
kubectl debug | デバッグ用のエフェメラルコンテナを追加 | kubectl debug my-pod -it --image=busybox | |
kubectl explain | リソースのフィールドを説明 | kubectl explain pod.spec.containers | |
kubectl api-resources | 利用可能なAPIリソースを表示 | kubectl api-resources | |
kubectl config get-contexts | コンテキスト一覧を表示 | kubectl config get-contexts | |
kubectl config current-context | 現在のコンテキストを表示 | kubectl config current-context | |
kubectl config use-context | コンテキストを切り替え | kubectl config use-context production | |
kubectl config set-context | コンテキストを設定 | kubectl config set-context my-ctx --cluster=my-cluster --user=admin | |
kubectl cluster-info | クラスター情報を表示 | kubectl cluster-info | |
kubectl config view | kubeconfig設定を表示 | kubectl config view --minify | |
kubectl version | クライアントとサーバーのバージョンを表示 | kubectl version --short |