I am using Fluentd as a sidecar to ship nginx logs to stdout so they show up in the Pod's logs. I have a strange problem that Fluentd is not picking up the configuration when the container starts.
Upon examining the Fluentd startup logs it appears that the configuration is not being loaded. The config is supposed to be loaded from /etc/fluentd-config/fluentd.conf when the container starts. I have connected to the container and the config file is correct, and the pv mounts are also correct. The environment variable also exists.
The full deployment spec is below - and is self contained if you feel like playing with it.
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
I got it to work by using stdout instead of redirecting to 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>