
Kubernetes作为容器编排的事实标准,在实际运维过程中会遇到各种问题。本文将系统性地介绍30个常见的Kubernetes集群问题及其诊断与解决方法,涵盖Pod、Node和集群层面的各类故障排查。
诊断方法:
kubectl describe pod <pod-name> -n <namespace>
kubectl logs <pod-name> -n <namespace>
kubectl get events --field-selector involvedObject.name=<pod-name> -n <namespace>解决方法:


诊断方法:
kubectl logs <pod-name> -n <namespace> --previous
kubectl describe pod <pod-name> -n <namespace>解决方法:
诊断方法:
kubectl exec -it <pod-name> -n <namespace> -- ping <service-name>
kubectl describe service <service-name> -n <namespace>解决方法:


诊断方法:
kubectl top pod <pod-name> -n <namespace>
kubectl exec -it <pod-name> -n <namespace> -- top解决方法:


诊断方法:
kubectl describe pod <pod-name> -n <namespace>
kubectl get nodes
kubectl describe node <node-name>解决方法:


诊断方法:
kubectl get nodes
kubectl describe node <node-name>
journalctl -u kubelet -f解决方法:

诊断方法:
kubectl exec -it <pod-name> -n <namespace> -- curl <service-name>
kubectl get pods -n kube-system解决方法:

诊断方法:
kubectl describe pod <pod-name> -n <namespace>
kubectl get pvc -n <namespace>
kubectl describe pvc <pvc-name> -n <namespace>解决方法:

诊断方法:
kubectl top node
kubectl describe node <node-name>解决方法:

诊断方法:
journalctl -u kubelet -f
kubeadm join --token <token> <master-ip>:<port> --discovery-token-ca-cert-hash sha256:<hash>解决方法:

诊断方法:
kubectl cluster-info
systemctl status kube-apiserver
journalctl -u kube-apiserver -f解决方法:

诊断方法:
kubectl get cs
systemctl status kube-controller-manager解决方法:

诊断方法:
kubectl get events --field-selector involvedObject.kind=Pod
systemctl status kube-scheduler解决方法:
诊断方法:
etcdctl endpoint health
etcdctl member list解决方法:
诊断方法:
kubectl get pods -n kube-system
kubectl logs <cni-pod-name> -n kube-system解决方法:
诊断方法:
kubectl get pv
kubectl get pvc
kubectl describe pvc <pvc-name>解决方法:
诊断方法:
kubectl describe pod <pod-name>
kubectl get pvc <pvc-name> -o yaml解决方法:
诊断方法:
kubectl get storageclass
kubectl describe storageclass <sc-name>解决方法:
诊断方法:
kubectl exec -it <pod-name> -- dd if=/dev/zero of=/mnt/test bs=1M count=1024
kubectl top pod <pod-name>解决方法:
诊断方法:
kubectl describe quota -n <namespace>
kubectl get resourcequotas -n <namespace>解决方法:
诊断方法:
kubectl auth can-i <verb> <resource>
kubectl get rolebindings,clusterrolebindings解决方法:
诊断方法:
openssl x509 -noout -text -in /etc/kubernetes/pki/apiserver.crt | grep Not
kubeadm certs check-expiration解决方法:
诊断方法:
kubectl get networkpolicy -A
kubectl describe networkpolicy <policy-name>解决方法:
诊断方法:
kubectl get psp
kubectl describe psp <psp-name>解决方法:
诊断方法:
kubectl describe pod <pod-name>
kubectl get secrets <secret-name> -o yaml解决方法:
诊断方法:
kubectl get crd
kubectl get <custom-resource>解决方法:
诊断方法:
kubectl get hpa
kubectl describe hpa <hpa-name>
kubectl top pod解决方法:
诊断方法:
kubectl get ingress
kubectl describe ingress <ingress-name>解决方法:
诊断方法:
kubectl get nodes
kubectl get pods -A -o wide解决方法:
诊断方法:
kubectl version
kubeadm upgrade plan解决方法:
典型症状:
诊断方法
# 检查 CoreDNS 状态
kubectl get pods -n kube-system -l k8s-app=kube-dns
# 测试 Service 解析
kubectl run -it --rm --restart=Never busybox --image=busybox -- nslookup <service-name>
# 检查网络策略
kubectl get networkpolicy --all-namespaces网络连通性测试:
# 创建一个临时的网络测试 Pod
kubectl run network-test --image=nicolaka/netshoot --restart=Never --rm -it -- /bin/bash
# 在测试 Pod 中执行 ping/telnet/curl 等命令
ping <target-pod-ip>
curl <service-name>:<port># 在运行的 Pod 中添加临时容器(需要启用 EphemeralContainers 特性)
kubectl debug -it <pod-name> --image=busybox --target=<container-name>
# 使用共享进程命名空间进行调试
kubectl run debugger --image=busybox --stdin --tty --share-processes --restart=Never# 使用 kubectl top 监控资源使用
kubectl top pods --sort-by=cpu
kubectl top nodes
# 启用 Kubernetes 审计日志# 修改 API Server 配置添加以下参数:
# --audit-policy-file=/etc/kubernetes/audit-policy.yaml
# --audit-log-path=/var/log/kubernetes/audit.log本文介绍了Kubernetes集群中30个常见问题的诊断与解决方法,涵盖了从Pod、Node到集群层面的各类问题。掌握这些排查技巧能够快速定位和解决Kubernetes环境中的问题,确保集群稳定运行。在实际操作中,建议结合监控告警系统,实现问题的早期发现和预防性维护。
如果你觉得这篇文章有用,欢迎点赞、转发、收藏、留言、推荐❤!
本文分享自 Nicholas与Pypi 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!