How to use nginx /dbg
Article Number: 000020126
Environment
Kubernetes environments with nginx-ingress-controller
Situation
What is the /dbg command?
/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.
Resolution
Using /dbg
This command needs to be run from inside one of the ingress-nginx pods, so first determine the pod to run it in.
> 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_POD=nginx-ingress-controller-n4p22
If 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.
> kubectl exec -n ingress-nginx $NGINX_POD /dbg general
{
"controllerPodsCount": 3
}
Viewing backend configuration
/dbg backends list will list the discovered backends:
> 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:
> kubectl exec -n ingress-nginx $NGINX_POD /dbg backends get cattle-system-rancher-80
Viewing 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:
> kubectl exec -n ingress-nginx $NGINX_POD /dbg certs get <fqdn>
Viewing dynamically generated nginx configuration
/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:
> kubectl exec -n ingress-nginx $NGINX_POD /dbg conf | grep "server_name example.com" -B2 -A20