Fluentd未从ConfigMap加载配置

时间:2019-06-08 11:10:50

标签: kubernetes fluentd

我使用Fluentd作为辅助工具,将nginx日志发送到stdout,以便它们显示在Pod的日志中。我有一个奇怪的问题,那就是容器启动时Fluentd不会选择配置。

检查Fluentd启动日志后,似乎未加载配置。应该在容器启动时从/etc/fluentd-config/fluentd.conf中加载配置。我已连接到容器,并且配置文件正确,并且PV安装也正确。环境变量也存在。

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

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

1 个答案:

答案 0 :(得分:1)

我通过使用stdout而不是重定向到localhost来使其工作。

- 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>
相关问题