使用Kubernetes中的fluentd读取容器日志时的权限问题

我对kubernetes非常陌生,并使用运行在GCE中的redis和mongodbtesting应用程序。 我想用fluentd来抓取我的日志文件并将它们发送到logz:

我使用以下fluentdconfiguration文件。 我在本地机器上testing了一个类似的版本。

<source> @type tail path /var/log/containers/squidex*.log pos_file /var/log/squidex.log.pos tag squidex.logs format json </source> <match squidex.logs> @type copy <store> @type logzio_buffered endpoint_url https://listener.logz.io:8071?token=... output_include_time true output_include_tags true buffer_type file buffer_path /fluentd/log/squidex.log.buffer flush_interval 10s buffer_chunk_limit 1m </store> <store> @type stdout </store> </match> 

我的kubernetesconfiguration是:

 --- apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: fluentd-logging labels: app: fluentd-logging spec: template: metadata: labels: app: fluentd-logging spec: containers: - name: fluentd image: gcr.io/squidex-157415/squidex-fluentd:latest resources: limits: memory: 200Mi requests: cpu: 40m volumeMounts: - name: varlog mountPath: /var/log terminationGracePeriodSeconds: 30 volumes: - name: varlog hostPath: path: /var/log 

几乎所有的工作,但是当我运行fluentd豆荚我看到这些豆荚日志输出中的以下条目:

 2017-04-22T09:49:22.286740784Z 2017-04-22 09:49:22 +0000 [warn]: /var/log/containers/squidex-282724611-3nhtw_default_squidex-ed7c437e677d3438c137cdc80110d106339999a6ba8e495a5752fe6d5da9e70d.log unreadable. It is excluded and would be examined next time 

我如何获得这些日志文件的权限?

这不是一个权限问题,但符号链接被破坏。 Kubernetes使用从/var/log/containers/var/log/pods/var/lib/docker/containers docker /var/log/containers符号链接。 您可以使用ls -la从群集的任何节点确认此项

您的DaemonSetconfiguration应该包含如下内容:

 volumeMounts: - name: varlog mountPath: /var/log/ readOnly: true - name: varlibdockercontainers mountPath: /var/lib/docker/containers readOnly: true [...] volumes: - name: varlog hostPath: path: /var/log/ - name: varlibdockercontainers hostPath: path: /var/lib/docker/containers 

这样,你就挂载了日志文件目录和符号链接的符号链接,这样你的fluentd就可以读取所有的东西了。