InfraLab
KUBERNETES67 cmd

Kubernetes (kubectl) チート集

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

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

67 / 67

CommandDescriptionExampleCopy
kubectl get podsPod一覧を表示kubectl get pods
kubectl get pods -A全Namespaceのpodを表示kubectl get pods -A
kubectl get pods -o widePod一覧を詳細情報付きで表示kubectl get pods -o wide
kubectl get pods -wPod一覧をリアルタイム監視kubectl get pods -w
kubectl describe podPodの詳細情報を表示kubectl describe pod my-pod
kubectl runPodを作成して実行kubectl run nginx --image=nginx --port=80
kubectl delete podPodを削除kubectl delete pod my-pod
kubectl delete pod --forcePodを強制削除kubectl delete pod my-pod --force --grace-period=0
kubectl get pods -lラベルでPodをフィルタリングkubectl get pods -l app=nginx
kubectl get pod -o yamlPodのYAML定義を表示kubectl get pod my-pod -o yaml
kubectl get deploymentsDeployment一覧を表示kubectl get deployments
kubectl create deploymentDeploymentを作成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 scaleDeploymentのレプリカ数を変更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 restartDeploymentを再起動kubectl rollout restart deployment/nginx
kubectl set imageコンテナイメージを更新kubectl set image deployment/nginx nginx=nginx:1.25
kubectl autoscaleHorizontal Pod Autoscalerを設定kubectl autoscale deployment nginx --min=2 --max=10 --cpu-percent=80
kubectl get svcService一覧を表示kubectl get svc
kubectl exposeリソースをServiceとして公開kubectl expose deployment nginx --port=80 --type=LoadBalancer
kubectl get ingressIngress一覧を表示kubectl get ingress
kubectl describe svcServiceの詳細情報を表示kubectl describe svc my-service
kubectl delete svcServiceを削除kubectl delete svc my-service
kubectl get endpointsEndpointsを表示kubectl get endpoints my-service
kubectl port-forward svcServiceへポートフォワードkubectl port-forward svc/my-service 8080:80
kubectl get configmapsConfigMap一覧を表示kubectl get configmaps
kubectl create configmapConfigMapを作成kubectl create configmap my-config --from-file=config.properties
kubectl get secretsSecret一覧を表示kubectl get secrets
kubectl create secret genericSecretを作成kubectl create secret generic my-secret --from-literal=password=mysecret
kubectl create secret tlsTLS Secretを作成kubectl create secret tls my-tls --cert=cert.pem --key=key.pem
kubectl describe configmapConfigMapの詳細を表示kubectl describe configmap my-config
kubectl get secret -o jsonpathSecretの値をデコードして表示kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -d
kubectl edit configmapConfigMapを編集kubectl edit configmap my-config
kubectl get namespacesNamespace一覧を表示kubectl get namespaces
kubectl create namespaceNamespaceを作成kubectl create namespace staging
kubectl delete namespaceNamespaceを削除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 nodesNode一覧を表示kubectl get nodes
kubectl describe nodeNodeの詳細情報を表示kubectl describe node worker-1
kubectl top nodesNodeのリソース使用量を表示kubectl top nodes
kubectl top podsPodのリソース使用量を表示kubectl top pods --sort-by=memory
kubectl cordonNodeをスケジュール不可に設定kubectl cordon worker-1
kubectl uncordonNodeをスケジュール可能に戻すkubectl uncordon worker-1
kubectl drainNodeからワークロードを退避kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data
kubectl taint nodesNodeにTaintを設定kubectl taint nodes worker-1 key=value:NoSchedule
kubectl logsPodのログを表示kubectl logs my-pod
kubectl logs -fPodのログをリアルタイム表示kubectl logs -f my-pod
kubectl logs --previous前回のコンテナのログを表示kubectl logs my-pod --previous
kubectl logs -c特定のコンテナのログを表示kubectl logs my-pod -c sidecar
kubectl exec -itPod内で対話的にコマンドを実行kubectl exec -it my-pod -- /bin/bash
kubectl port-forwardPodへポートフォワード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 viewkubeconfig設定を表示kubectl config view --minify
kubectl versionクライアントとサーバーのバージョンを表示kubectl version --short
Related