kubectl get pods -A -o wide
kubectl get nodes -o wide
kubectl get events -A --sort-by=.lastTimestamp
kubectl describe pod <pod> -n <ns>
kubectl logs <pod> -n <ns> --previous
kubectl logs <pod> -n <ns> -c <container> -f
kubectl exec -it <pod> -n <ns> -- sh
kubectl top pod -n <ns>
kubectl top node
kubectl rollout status deploy/<name> -n <ns>
kubectl rollout history deploy/<name> -n <ns>
kubectl rollout undo deploy/<name> -n <ns>
kubectl port-forward svc/<name> 8080:80 -n <ns>
kubectl auth can-i --list -n <ns>
kubectl api-resources
kubectl cordon <node>
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
| 现象 | 先看 |
|---|---|
| Pod Pending | describe pod 的 Events、节点资源、taints、PVC |
| CrashLoopBackOff | logs --previous、退出码、探针、内存 limit |
| ImagePullBackOff | 镜像名/tag、imagePullSecrets、节点网络 |
| Pod Evicted | 节点 DiskPressure/MemoryPressure、磁盘和日志 |
| 节点 NotReady | kubelet、容器运行时、CNI、磁盘/内存 |
| Service 不通 | Endpoints、selector、NetworkPolicy、kube-proxy |
| 集群 DNS 失败 | CoreDNS Pod、kube-dns Endpoints、53 端口策略 |
| PVC Pending | StorageClass、provisioner、容量/access mode |
kubectl logs 只显示当前容器;重启前的日志要加 --previous。describe 的 Events 只保留最近一段时间,排障要尽快看。exec 需要容器里有 shell;distroless 镜像要用 debug 容器或 kubectl debug。drain 会驱逐 Pod;先确认副本和 PDB,别把单副本服务打挂。-n 和 --context。kubectl top 需要 metrics-server;没装时不是节点资源不足。合上页面,先回答,再展开对照。
kubectl logs <pod> --previous 查看上一个容器实例的日志。kubectl debug 注入临时调试容器,或使用带 shell 的调试镜像/副本。
小程序版
微信扫码,随时查命令