集群信息:

  1. 显示 Kubernetes 版本:kubectl version
  2. 显示集群信息:kubectl cluster-info
  3. 列出集群中的所有节点:kubectl get nodes
  4. 查看一个具体的节点详情:kubectl describe node
  5. 列出所有命名空间:kubectl get namespaces
  6. 列出所有命名空间中的所有 pod:kubectl get pods --all-namespaces Pod 诊断:
  7. 列出特定命名空间中的 pod:kubectl get pods -n
  8. 查看一个 Pod 详情:kubectl describe pod
  9. 查看 Pod 日志:kubectl logs
  10. 尾部 Pod 日志:kubectl logs -f
  11. 在 pod 中执行命令:kubectl exec -it
  12. 检查 Pod 准备情况:kubectl get pods -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
  13. 检查 Pod 事件:kubectl get events -n Service诊断:
  14. 列出命名空间中的所有服务:kubectl get svc -n
  15. 查看一个服务详情:kubectl describe svc Deployment诊断:
  16. 列出命名空间中的所有Deployment:kubectl get deployments -n
  17. 查看一个Deployment详情:kubectl describe deployment
  18. 查看滚动发布状态:kubectl rollout status deployment/
  19. 查看滚动发布历史记录:kubectl rollout history deployment/ StatefulSet诊断:
  20. 列出命名空间中的所有 StatefulSet:kubectl get statefulsets -n
  21. 查看一个 StatefulSet详情:kubectl describe statefulset ConfigMap 和Secret诊断:
  22. 列出命名空间中的 ConfigMap:kubectl get configmaps -n
  23. 查看一个ConfigMap详情:kubectl describe configmap
  24. 列出命名空间中的 Secret:kubectl get secrets -n
  25. 查看一个Secret详情:kubectl describe secret 命名空间诊断:
  26. 查看一个命名空间详情:kubectl describe namespace 资源使用情况:
  27. 检查 pod 的资源使用情况:kubectl top pod
  28. 检查节点资源使用情况:kubectl top nodes 网络诊断:
  29. 显示命名空间中 Pod 的 IP 地址:kubectl get pods -n -o custom-columns=POD:metadata.name,IP:status.podIP --no-headers
  30. 列出命名空间中的所有网络策略:kubectl get networkpolicies -n
  31. 查看一个网络策略详情:kubectl describe networkpolicy 持久卷 (PV) 和持久卷声明 (PVC) 诊断:
  32. 列出PV:kubectl get pv
  33. 查看一个PV详情:kubectl describe pv
  34. 列出命名空间中的 PVC:kubectl get pvc -n
  35. 查看PVC详情:kubectl describe pvc 节点诊断:
  36. 获取特定节点上运行的 Pod 列表: kubectl get pods --field-selector spec.nodeName= 资源配额和限制:
  37. 列出命名空间中的资源配额:kubectl get resourcequotas -n
  38. 查看一个资源配额详情:kubectl describe resourcequota 自定义资源定义 (CRD) 诊断:
  39. 列出命名空间中的自定义资源:kubectl get
  40. 查看自定义资源详情:kubectl describe 使用这些命令时,请记住将<namespace>, <pod-name>, <service-name>, <deployment-name>, <statefulset-name>, <configmap-name>, <secret-name>, <namespace-name>, <pv-name>, <pvc-name>, <node-name>, <network-policy-name>, <resource-quota-name>, <custom-resource-name>和替换为你的特定值。这些命令应该可以帮助你诊断 Kubernetes 集群以及在其中运行的应用程序。 资源伸缩和自动伸缩:
  41. Deployment伸缩:kubectl scale deployment
  42. 设置Deployment的自动伸缩:kubectl autoscale deployment
  43. 检查水平伸缩器状态:kubectl get hpa -n 作业和 CronJob 诊断:
  44. 列出命名空间中的所有作业:kubectl get jobs -n
  45. 查看一份工作详情:kubectl describe job
  46. 列出命名空间中的所有 cron 作业:kubectl get cronjobs -n
  47. 查看一个 cron 作业详情:kubectl describe cronjob 容量诊断:
  48. 列出按容量排序的持久卷 (PV):kubectl get pv --sort-by=.spec.capacity.storage
  49. 查看PV回收策略:kubectl get pv -o=jsonpath='{.spec.persistentVolumeReclaimPolicy}'
  50. 列出所有存储类别:kubectl get storageclasses Ingress和服务网格诊断:1. 列出命名空间中的所有Ingress:kubectl get ingress -n
  51. 查看一个Ingress详情:kubectl describe ingress
  52. 列出命名空间中的所有 VirtualServices (Istio):kubectl get virtualservices -n
  53. 查看一个 VirtualService (Istio)详情:kubectl describe virtualservice Pod 网络故障排除:
  54. 运行网络诊断 Pod(例如 busybox)进行调试:kubectl run -it --rm --restart=Never --image=busybox net-debug-pod -- /bin/sh
  55. 测试从 Pod 到特定端点的连接:kubectl exec -it
  56. 跟踪从一个 Pod 到另一个 Pod 的网络路径:kubectl exec -it
  57. 检查 Pod 的 DNS 解析:kubectl exec -it 配置和资源验证:
  58. 验证 Kubernetes YAML 文件而不应用它:kubectl apply --dry-run=client -f
  59. 验证 pod 的安全上下文和功能:kubectl auth can-i list pods --as=system:serviceaccount:: RBAC 和安全性:
  60. 列出命名空间中的角色和角色绑定:kubectl get roles,rolebindings -n
  61. 查看角色或角色绑定详情:kubectl describe role 服务帐户诊断:
  62. 列出命名空间中的服务帐户:kubectl get serviceaccounts -n
  63. 查看一个服务帐户详情:kubectl describe serviceaccount 清空节点和解除封锁:
  64. 清空节点以进行维护:kubectl drain --ignore-daemonsets
  65. 解除对节点的封锁:kubectl uncordon 资源清理:
  66. 强制删除 pod(不推荐):kubectl delete pod --grace-period=0 --forcePod 亲和性和反亲和性:
  67. 列出 pod 的 pod 亲和性规则:kubectl get pod -o=jsonpath='{.spec.affinity}'
  68. 列出 pod 的 pod 反亲和性规则:kubectl get pod -o=jsonpath='{.spec.affinity.podAntiAffinity}' Pod 安全策略 (PSP):
  69. 列出所有 Pod 安全策略(如果启用):kubectl get psp 事件:
  70. 查看最近的集群事件:kubectl get events --sort-by=.metadata.creationTimestamp
  71. 按特定命名空间过滤事件:kubectl get events -n 节点故障排除:
  72. 检查节点情况:kubectl describe node | grep Conditions -A5
  73. 列出节点容量和可分配资源:kubectl describe node | grep -E "Capacity|Allocatable" 临时容器(Kubernetes 1.18+):
  74. 运行临时调试容器:kubectl debug -it kuelet诊断:
  75. 查看节点上的kubelet日志:kubectl logs -n kube-system kubelet- 使用Telepresence 进行高级调试:
  76. 使用 Telepresence 调试 pod:telepresence --namespace Kubeconfig 和上下文:
  77. 列出可用的上下文:kubectl config get-contexts
  78. 切换到不同的上下文:kubectl config use-context Pod 安全标准(PodSecurity 准入控制器):1. 列出 PodSecurityPolicy (PSP) 违规行为:kubectl get psp -A | grep -vE 'NAME|REVIEWED' Pod 中断预算 (PDB) 诊断:
  79. 列出命名空间中的所有 PDB:kubectl get pdb -n
  80. 查看一个PDB详情:kubectl describe pdb 资源锁诊断(如果使用资源锁):
  81. 列出命名空间中的资源锁:kubectl get resourcelocks -n 服务端点和 DNS:
  82. 列出服务的服务端点:kubectl get endpoints
  83. 检查 Pod 中的 DNS 配置:kubectl exec -it -- cat /etc/resolv.conf 自定义指标(Prometheus、Grafana):
  84. 查询Prometheus指标:用于kubectl port-forward访问Prometheus和Grafana服务来查询自定义指标。 Pod 优先级和抢占:
  85. 列出优先级:kubectl get priorityclasses Pod 开销(Kubernetes 1.18+):
  86. 列出 pod 中的开销:kubectl get pod -o=jsonpath='{.spec.overhead}' 存储卷快照诊断(如果使用存储卷快照):
  87. 列出存储卷快照:kubectl get volumesnapshot -n
  88. 查看存储卷快照详情:kubectl describe volumesnapshot -o=json 节点污点:
  89. 列出节点污点:kubectl describe node | grep Taints 更改和验证 Webhook 配置:
  90. 列出变异 webhook 配置:kubectl get mutatingwebhookconfigurations
  91. 列出验证 Webhook 配置:kubectl get validatingwebhookconfigurationsPod 网络策略:
  92. 列出命名空间中的 pod 网络策略:kubectl get networkpolicies -n 节点条件(Kubernetes 1.17+):
  93. 自定义查询输出:kubectl get nodes -o custom-columns=NODE:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status -l 'node-role.kubernetes.io/worker=' 审核日志:
  94. 检索审核日志(如果启用):检查 Kubernetes 审核日志配置以了解审核日志的位置。 节点操作系统详细信息:1. 获取节点的操作系统信息:kubectl get node 、、等占位符替换为你的集群和用例的实际值。

总结:排错三兄弟(重点)

95.kubectl get

96.kubectl describe

97.kubectl logs