kubernetes集群部署 Debug

官方文档中有Troubleshooting这个主题,包含以下内容:

  • Debug Pods

  • Debug Services

  • Debug a StatefulSet

  • Debug Init Containers

  • Debug Running Pods

  • Determine the Reason for Pod Failure

  • Get a Shell to a Running Container

里面有常见问题的排查方法介绍

常见套路

1. 使用 busybox

  • 方法一:kubectl run curl --image=radial/busyboxplus:curl -i --tty
  • 方法二:kubectl debug targetPod -it --image=busybox

2. 使用 initContainer

  • 给Pod、Deployment增加 initContainer,在其中添加debug操作。
  • 推荐阅读文档: 链接
  • 查看 initContainer 日志:
    • kubectl logs pod_name -c initContainerName

3. 查看集群kube-system命名空间下的pod和日志

1
2
kubectl get pod -n kube-system
kubectl logs --namespace=kube-system -l k8s-app=kube-dns

4. DNS 相关问题的排查

  • 推荐阅读:文档
  • 使用 nslookup 检查服务是否可访问
    1
    2
    3
    4
    
    $ kubectl run dnsutils --image=tutum/dnsutils --command -- sleep infinity
    $ kubectl exec -it dnsutils -- bash
    # 进入pod后:
    $ nslookup service_name
    

5. 连通相关问题排查

  • Pod 和 Pod 之间的相连
  • Pod 和 Service 之间的相连
  • Service 和 Service 之间的相连

一般步骤:

  • 检查服务程序绑定地址是不是0.0.0.0
  • 检查端口暴露是否正确
  • 检查DNS解析,查看DNS服务是否正常