kubectl 指令速查表
適用於 Kubernetes 1.30+ 的 Kubernetes CLI 指令:檢查 Pod、Deployment、Service、日誌、exec 偵錯、滾動發布、Context 與 JSONPath 查詢。
運作原理
kubectl reads and reconciles declarative resource manifests against the API server: `get`/`describe`/`logs` diagnose state, while `apply`/`rollout` safely drive cluster changes.
生存指南
最先需要掌握的少數核心指令。
42 個指令
Contexts, Namespaces & Discovery
Verify which cluster and namespace you target before reading or changing state.
- 必備
Print the currently active cluster context before running commands
kubectl config current-context使用時機
Prevents accidentally running dev commands against a production cluster.
範例
kubectl config current-context
Inspect, Logs & Events
Diagnose CrashLoopBackOff, ImagePullBackOff, pending pods, and probe failures.
Shell, Port-Forward & Copy
Connect to cluster services locally, exec into pods, and transfer files.
Apply, Dry-Run & Rollouts
Validate manifests safely, watch rollouts, scale, and roll back cleanly.
Nodes, RBAC & Cleanup
Verify permissions, check resource usage, cordon nodes, and clean pods.