How can I write access log as file in k8s ingress installed by helm chart

Hi.

I want to collect access log by collector that read all logfiles in /var/log path and run as daemonset in a namespace.

I installed traefik as helm chart - GitHub web editor

I add mount to volumes and additionalVolumeMounts in values.yaml.

deployment:
  additionalVolumes:
    - name: traefik-logs
      emptyDir: {}

additionalVolumeMounts:
  - name: traefik-logs
    mountPath: /var/log

I add filePath in log.general & log.access

logs:
  general:
    level: ERROR
    filePath: /var/log/traefik.log
  access:
    filePath: /var/log/traefik-access.log

But, there is any log file in /var/log.
There is no config as parameter on process related to log file.

$ ps aux | grep traefik

1 65532 0:00 traefik traefik --global.checknewversion --global.sendanonymoususage --entrypoints.metrics.address=:9100/tcp --entrypoints.traefik.address=:9000/tcp --entrypoints.web.address=:8000/tcp --entrypoints.websecure.address=:8443/tcp --api.dashboard=true --ping=true --metrics.prometheus=true --metrics.prometheus.entrypoint=metrics --providers.kubernetescrd --providers.kubernetesingress --accesslog=true --accesslog.format=json --accesslog.fields.defaultmode=keep --accesslog.fields.headers.defaultmode=keep

I tested it again to fix mount path to /var/log/traefik. /var/log/traefik dir is created. Volume seems to be amounted. But traefik filepath config seems to be not working.

Hello @joey-yoonsung

Did you check the path /var/log directly into Traefik container? The logs files should be created and stored inside a container.

@jakubhajek

Yes. there is.
I access the container as shell like bellow

kubectl get pod | grep traefik                                                                    ✔  1h 53m 43s  ladp-vks-120-dev ⎈  13:45:38 
traefik-7788b7c8c7-x9w24                          1/1     Running   0          114m
kubectl exec -it traefik-7788b7c8c7-x9w24 /bin/sh
 $ cd var/log
/var/log $ ls -al
total 0
drwxrwsrwx    2 root     65532            6 Apr 12 02:50 .
drwxr-xr-x    1 root     root            21 Apr 12 02:50 ..

I tried to set more change of configurations, but there is no different.

filePath key in logs, logs.general, logs.access seems to be ignored.

Very hard to configure traefik in k8s because the official document doesn't care about config in k8s.

I found it!

filePath is not working in logs , logs.general , logs.access.

The filepath can be set by additionalArguments in values.yaml

deployment:
  additionalVolumes:
    - name: traefik-logs
      emptyDir: {}

additionalVolumeMounts:
  - name: traefik-logs
    mountPath: /var/log/traefik

additionalArguments:
  - "--log.filepath=/var/log/traefik/traefik.log"
  - "--accesslog.filepath=/var/log/traefik/traefik-access.log"

Then the process run with these parameters.

ps aux | grep traefik
1 65532     0:00 traefik traefik --global.checknewversion --global.sendanonymoususage --entrypoints.metrics.address=:9100/tcp --entrypoints.traefik.address=:9000/tcp --entrypoints.web.address=:8000/tcp --entrypoints.websecure.address=:8443/tcp --api.dashboard=true --ping=true --metrics.prometheus=true --metrics.prometheus.entrypoint=metrics --providers.kubernetescrd --providers.kubernetesingress --accesslog=true --accesslog.format=json --accesslog.fields.defaultmode=keep --accesslog.fields.headers.defaultmode=keep --log.filepath=/var/log/traefik/traefik.log --accesslog.filepath=/var/log/traefik/traefik-access.log

But it has limitations. The stdout that streamed the traefik app log and access log both before don't stream access log anymore.

1 Like

You can have a look at the workshop we have prepared to let Kubernetes users start with Traefik:

1 Like