Kubernetes 排障命令速查

常用命令

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

易错点

相关命令