【问题标题】:Fluentd not loading config from ConfigMapFluentd 未从 ConfigMap 加载配置
【发布时间】:2019-06-08 11:10:50
【问题描述】:

我使用 Fluentd 作为 sidecar 将 nginx 日志发送到标准输出,以便它们显示在 Pod 的日志中。我有一个奇怪的问题,容器启动时 Fluentd 没有拾取配置。

在检查 Fluentd 启动日志时,似乎没有加载配置。配置应该在容器启动时从 /etc/fluentd-config/fluentd.conf 加载。我已经连接到容器并且配置文件是正确的,并且 pv mounts 也是正确的。环境变量也存在。

完整的部署规范如下 - 如果您想玩它,它是独立的。

apiVersion: v1
kind: List
items:
- apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: weblog-pv
    labels:
      type: local
  spec:
    storageClassName: manual
    accessModes: 
    - ReadWriteOnce
    hostPath:
      path: /tmp/weblog
      type: DirectoryOrCreate
    capacity: 
      storage: 500Mi

- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: weblog-pvc
  spec:
    storageClassName: manual
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 200Mi

- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: fluentd-config
  data:
    fluentd.conf: |
      <source>
        @type tail
        format none
        path /var/log/nginx/access.log
        tag count.format1
      </source>
      <match *.**>
        @type forward
        <server>
          name localhost
          host 127.0.0.1
        </server>
      </match>

- apiVersion: v1
  kind: Pod
  metadata:
    name: sidecar-example
    labels:
      app: webserver
  spec:
    containers:
    - name: nginx
      image: nginx:latest
      ports: 
      - containerPort: 80
      volumeMounts:
      - name: logging-vol
        mountPath: /var/log/nginx
    - name: fdlogger
      env:
        - name: FLUENTD_ARGS
          value: -c /etc/fluentd-config/fluentd.conf
      image: fluent/fluentd
      volumeMounts:
      - name: logging-vol
        mountPath: /var/log/nginx
      - name: log-config
        mountPath: /etc/fluentd-config
    volumes:
      - name: logging-vol
        persistentVolumeClaim: 
          claimName: weblog-pvc
      - name: log-config
        configMap:
          name: fluentd-config

- apiVersion: v1
  kind: Service
  metadata:
    name: sidecar-svc
  spec:
    selector:
      app:  webserver
    type: NodePort
    ports:
    - name:  sidecar-port
      port:  80
      nodePort:  32000

【问题讨论】:

  • 你解决了吗?在可能的情况下,我给出的 configmap 数据也没有被考虑。

标签: kubernetes fluentd


【解决方案1】:

我通过使用标准输出而不是重定向到本地主机来让它工作。

- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: fluentd-config
  data:
    fluent.conf: |
      <source>
        @type tail
        format none
        path /var/log/nginx/access.log
        tag count.format1
      </source>
      <match *.**>
        @type stdout
      </match>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 2018-08-05
    相关资源
    最近更新 更多