Anil G
Anil G

Reputation: 187

How to mimic "--log-driver=syslog" in Kubernetes

With docker, I can pass log-driver=syslog command line option to forward container logs to syslog. How do I pass these docker arguments via Kubernetes yaml/json descriptor?

Upvotes: 8

Views: 8135

Answers (4)

Victor Fialkin
Victor Fialkin

Reputation: 164

You can setup container runtime properties in /etc/docker/daemon.json

sudo sh -c 'echo "{\"log-driver\":\"syslog\"}"  > /etc/docker/daemon.json'

kubernetes.io\Container runtimes

Upvotes: 0

linehrr
linehrr

Reputation: 1748

it's been discussed for quite a while here in this thread: https://github.com/kubernetes/kubernetes/issues/15478, however k8s community really recommend to have your own dedicated log agent. you can choose to run it under each host machine or use it as sidecar or more recommended as a DaemonSet.

see details here: https://kubernetes.io/docs/concepts/cluster-administration/logging/#cluster-level-logging-architectures

since k8s is leaving dockerd and moving to containerd, you will not even have the option to configure dockerd logging driver and log opts. so you either can wait for k8s community to add logging driver opts or use one of the above approaches.

Upvotes: 0

Zhi Yuan
Zhi Yuan

Reputation: 890

i dont think kubernetes need to do such --log-driver options in pod json file. As my experience, you can set such setting in docker service. i.e check

/etc/systemd/system/docker.service

and set ExecStart=/usr/bin/docker daemon --log-driver=json-file blablabla. more information could be get here: https://docs.docker.com/engine/admin/logging/overview/#configure-logging-drivers

further more, if you don't set this --log-driver, by default the json file will be created, which collected all logs of your containers in kubernetes pods, you can find those files on

your_docker_runtime_root/docker/containers/container_id/container_id-json.json

Upvotes: 2

Michael Hausenblas
Michael Hausenblas

Reputation: 13941

Starting with the available documentation: in your case on logging and volumes. Taking these two sources together we arrive at something like the following:

...
containers:
  - name: syslogtest
    image: ubuntu:14.04
    volumeMounts:
      - name: logvol
        mountPath: /dev/log
        readOnly: false
volumes:
  - name: logvol
    source:
      hostDir:
        path: /dev/log
...

Upvotes: 4

Related Questions