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?
-
I really like this feature as well, since we want to stream the logs via syslog driver to our logstash. however k8s does not seem to like this idea. and file mount seems a bit too complicated and not very agile. I wish they add this support later, just like Swarm can do this.– linehrrApr 1, 2019 at 16:51
4 Answers
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
...
-
2I am looking at using the --log-driver=syslog docker option rather than mounting volumes. That way I can follow the best practice of building a docker image such that the container logs to stdout/stderr but on cloud, by setting --log-driver=syslog/fluentd I can collect the logs to a central logging store like elasticsearch.– Anil GNov 18, 2015 at 6:19
-
As I said, above is the best practice, see also example github.com/kubernetes/kubernetes/blob/release-1.0/contrib/… Nov 18, 2015 at 6:26
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
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.
You can setup container runtime properties in /etc/docker/daemon.json
sudo sh -c 'echo "{\"log-driver\":\"syslog\"}" > /etc/docker/daemon.json'