首页/云/云与容器速查/kubectl debug 临时调试容器
本包目录(340 条)

kubectl debug 临时调试容器

生产镜像常是精简/无 shell 的:kubectl debug 挂临时容器进同命名空间排查,或做节点级调试,不动业务镜像本身。

云与容器速查云更新于 2026-10-12
Pod 内调试kubectl debug -it <pod> --image=nicolaka/netshoot --target=<容器>
复制重建kubectl debug <pod> --copy-to=debug-pod --image=busybox 改配置复现
节点级kubectl debug node/<node> -it --image=busybox,宿主根挂在 /host
关键参数--target 让临时容器共享目标容器的进程命名空间
限制ephemeral 容器不能配端口与资源,仅用于调试

调试命令

调试命令
kubectl debug -it web-1 --image=nicolaka/netshoot --target=web
# 节点级:对比宿主环境与内核
kubectl debug node/node-1 -it --image=busybox
ps aux
cat /host/etc/os-release
容器没 shell 时优先加临时调试容器,而不是重建业务 Pod;只有要复现带配置变更的启动问题时才用 --copy-to。

易错点

  • 对 distroless 镜像直接 kubectl exec:exec 入口不存在,改用 debug
  • 忘了 --target:临时容器不在目标进程命名空间,ps 看不到业务进程

数据来源与参考

  • Kubernetes Docs:Debugging Pods
  • Kubernetes Docs:Debugging Kubernetes Nodes

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌