What is the /dbg command?什么是 /dbg 命令/dbg is a program included in the ingress-nginx container image that can be used to show information about the nginx environment and the resulting nginx configuration, which can be helpful when debugging ingress issues in Kubernetes./dbg 是包含在 ingress-nginx 容器镜像中的程序可用于展示 nginx 环境及其生成的 nginx 配置信息这在调试 Kubernetes 入门问题时非常有帮助。Resolution 结局Using /dbg 使用 /dbgThis command needs to be run from inside one of the ingress-nginx pods, so first determine the pod to run it in.这个命令需要在某个 ingress-nginx pod 内部运行所以先确定要运行的 pod。 kubectl get pods -n ingress-nginx NAME READY STATUS RESTARTS AGE default-http-backend-67cf578fc4-54jlz 1/1 Running 0 5d nginx-ingress-controller-56nss 1/1 Running 0 5d nginx-ingress-controller-hscfg 1/1 Running 0 4d21h nginx-ingress-controller-n4p22 1/1 Running 0 5d export NGINX_PODnginx-ingress-controller-n4p22If you are diagnosing specific connection issues, you can determine which controller is receiving the traffic by looking through the logs of each.如果你在诊断具体的连接问题可以通过查看每个控制器的日志来确定是哪个控制器接收了流量。Viewing ingress-controller status查看入口-控制器状态/dbg general will show the count of running controllers./dbg general 会显示运行控制器的数量。 kubectl exec -n ingress-nginx $NGINX_POD /dbg general { controllerPodsCount: 3 }Viewing backend configuration查看后端配置/dbg backends list will list the discovered backends:/DBG 后端列表将列出已发现的后端 kubectl exec -n ingress-nginx $NGINX_POD /dbg backends list cattle-system-rancher-80 upstream-default-backend/dbg backends get will show the configuration for the named backend:/dbg 后端 get 会显示命名后端的配置 kubectl exec -n ingress-nginx $NGINX_POD /dbg backends get cattle-system-rancher-80Viewing ingress certificate data查看入口证书数据/dbg certs will dump the x509 cert and key for a certificate that nginx has discovered from k8s secrets for the given hostname:/dbg 证书会倾倒 nginx 从 k8s 秘密中发现的 x509 证书和密钥该证书针对给定主机名 kubectl exec -n ingress-nginx $NGINX_POD /dbg certs get fqdnViewing dynamically generated nginx configuration查看动态生成的 nginx 配置/dbg conf will dump the dynamically generated nginx configuration. To view the configuration for a specific ingress hostname, you could run /dbg conf and then grep for the server_name:/dbg conf 会导出动态生成的 nginx 配置。要查看特定入口主机名的配置可以运行 /dbg conf然后用 grep 获取 server_name kubectl exec -n ingress-nginx $NGINX_POD /dbg conf | grep server_name example.com -B2 -A20Cause 病因Additional Information 附加信息Environment 环境Kubernetes environments with nginx-ingress-controller带有 nginx-ingress-controller 的 Kubernetes 环境nginx /dbg 是什么与如何使用nginx /dbg并非标准 Nginx 核心的内置功能而是Kubernetes ingress-nginx 控制器提供的专用调试工具用于快速检查和诊断运行中的 Nginx Ingress 实例状态。它是一个命令行工具通常位于 Ingress 容器的/dbg路径下帮助运维人员排查路由配置、后端服务、证书等相关问题。一、核心定位与适用场景定位ingress-nginx 官方调试工具用于实时检查Nginx 配置、后端服务、upstream 状态、证书信息等适用仅适用于 Kubernetes 环境中的 ingress-nginx 控制器不适用于独立部署的标准 Nginx用途排查路由转发异常404/502/503 等验证动态配置是否正确加载检查证书有效性与匹配情况查看 upstream 后端健康状态收集调试信息用于问题诊断二、使用方法Kubernetes 环境1. 进入 Ingress 容器首先通过 kubectl 进入运行中的 ingress-nginx Pod 容器bash运行kubectl exec -it -n 命名空间 ingress-pod-name -- bash # 示例默认命名空间通常为 ingress-nginx kubectl exec -it -n ingress-nginx ingress-nginx-controller-7f98d6f5b4-2x7z9 -- bash2. 执行 /dbg 命令在容器内直接运行/dbg可查看所有可用子命令bash运行/dbg # 输出示例 Available Commands: backends Inspect the dynamically-loaded backends information certs Inspect certificate information config Output the full nginx configuration help Help about any command info Show information about the nginx instance server Inspect server configuration upstream Inspect upstream information3. 常用子命令详解表格命令功能示例/dbg config输出完整 Nginx 配置/dbg config/dbg backends all查看所有动态后端服务信息JSON 格式/dbg backends all/dbg certs查看所有加载的证书信息/dbg certs/dbg upstream查看 upstream 集群状态/dbg upstream/dbg info显示 Nginx 实例基本信息/dbg info/dbg server查看虚拟主机配置/dbg server4. 进阶用法过滤输出结合 grep/jq 处理 JSON 结果bash运行/dbg backends all | jq .items[] | {name: .name, service: .service}导出配置将完整配置保存到本地bash运行/dbg config /tmp/nginx.conf # 从容器复制到本地 kubectl cp -n ingress-nginx ingress-nginx-controller-7f98d6f5b4-2x7z9:/tmp/nginx.conf ./local-nginx.conf访问Rancher-K8S解决方案博主企业合作伙伴 https://blog.csdn.net/lidw2009