【问题标题】:Permission issue when reading container logs with fluentd in Kubernetes在 Kubernetes 中使用 fluentd 读取容器日志时的权限问题
【发布时间】:2017-04-22 10:21:02
【问题描述】:

我对 kubernetes 非常陌生,并且在 GCE 中运行了带有 redis 和 mongodb 的测试应用程序。我想用 fluentd 获取我的日志文件并将它们发送到 logz:

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

<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

几乎一切正常,但是当我运行 fluentd 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

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

【问题讨论】:

  • 我认为您的问题是 /var/log/containers 并没有真正保存日志文件,而是链接到它们。应该链接到持有容器的FS。所以你可能应该同时安装两个

标签: docker kubernetes fluentd


【解决方案1】:

这不是权限问题,而是符号链接损坏。 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

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

【讨论】:

  • 我正在安装两个目录。仍然收到 Permission Denied 错误。我还检查了/bin/sh
猜你喜欢
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-02
  • 1970-01-01
  • 1970-01-01
  • 2021-04-11
  • 2019-04-24
相关资源
最近更新 更多