Ingress controller not showing nginx access/error logs

kubernetesnginx-ingress

I'm trying to troubleshoot a 404 message on my ingress. When I view logs using kubectl logs -n ingress-nginx ingress-nginx-controller-xxxxxx -f I don't see any output when making a request to the URL. Is there a specific setting that allows me to see access/error logs?

I'm looking for what I would normally see when viewing /var/log/nginx/error.log or /var/log/nginx/access.log.

Best Answer

You can exec into the pods using kubectl exec <pod_name> -n <namespace> <command> and check if your application is creating log files in the paths that you have mentioned. If you are able to verify the existence of those files, you can add a busybox sidecar to the deployment and you can directly stream your logs using the sidecar and tail them using kubectl logs

You can use the following template to do the same:

Add the following volume-mount to the existing deployment

volumeMounts:
  - mountPath: /var/log/nginx
    name: logging-mount

And then you can add the sidecar using the following template

- name: log-streaming-sidecar
  image: busybox
  args: [/bin/sh, -c, 'tail -n+1 -f /var/log/nginx/*']
  volumeMounts:
     - mountPath: /var/log/nginx
       name: logging-mount
volumes:
  - name: logging-mount
    emptyDir: {}

Please note that this will stream both your error and access logs into the same stream. Although, the correct method to do this is to create symlinks for error and access logs, the method I have mentioned can be used as an alternative.

Hope this helps!