阅读容易记录Kubernetes的容器日志时的权限问题

时间:2017-04-22 10:21:03

标签: docker kubernetes fluentd

我是kubernetes的新手,并且在GCE中运行redis和mongodb的测试应用程序。我想用流利的格式化我的日志文件并将它们发送到logz:

我使用以下流利的配置文件。我在本地机器上测试了类似的版本。

<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>

我的kubernetes配置是:

---
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

几乎一切正常,但是当我运行流畅的pod时,我在这些pod的日志输出中看到以下条目:

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

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

1 个答案:

答案 0 :(得分:4)

这不是权限问题,而是符号链接损坏。 Kubernetes正在使用从/var/log/containers/var/log/pods/var/lib/docker/containers的符号链接。您可以使用ls -la

从群集的任何节点进行确认

您的DaemonSet配置应包含以下内容:

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

这样,您将挂载日志文件目录和符号链接的符号链接,以便您的流利者可以读取所有内容。