We can have the config files retrieved from configMap ,Instead of baking the fluentd conf files inside the docker image. This would eneble user to give custom configurations.
In my fluentd version 1.2.2 installation I replace config files using a config map mounted into the fluent config path like so:
volumeMounts:
- name: config-volume
mountPath: /fluentd/etc
and for the volume:
volumes:
- name: config-volume
configMap:
name: fluentd-config
*I have added the fluentd version
@vpistis
I replace config files
will fail in k8s, because of:
configMap is ROFix impact:
Secret, configMap, downwardAPI and projected volumes will be mounted as read-only volumes. Applications that attempt to write to these volumes will receive read-only filesystem errors.
sed here https://github.com/fluent/fluentd-kubernetes-daemonset/blob/master/docker-image/v0.12/alpine-elasticsearch/entrypoint.sh#L6-L12if [ -z ${FLUENT_ELASTICSEARCH_USER} ] ; then
sed -i '/FLUENT_ELASTICSEARCH_USER/d' /fluentd/etc/${FLUENTD_CONF}
fi
if [ -z ${FLUENT_ELASTICSEARCH_PASSWORD} ] ; then
sed -i '/FLUENT_ELASTICSEARCH_PASSWORD/d' /fluentd/etc/${FLUENTD_CONF}
fi
sed: can't create temp file '/fluentd/etc/fluent.confXXXXXX': Read-only file system
the issue is still open for k8s
@tuchodi I'm sorry, but I'm not specified that I used the configMap for fluentd 1.2.2 version, and I don't see the RO error.
@vpistis
configMap clearly specified here https://github.com/fluent/fluentd-kubernetes-daemonset/issues/174#issuecomment-405254408:
and for the volume:
volumes: - name: config-volume configMap: name: fluentd-config
it will fail unless you are providing FLUENT_ELASTICSEARCH_USER and FLUENT_ELASTICSEARCH_PASSWORD in env
@tuchodi
it will fail unless you are providing FLUENT_ELASTICSEARCH_USER and FLUENT_ELASTICSEARCH_PASSWORD in env
correct!
...and last but not least, I use fluentd with MongoDB and not Elasticsearch 馃槑 .
Using the configMap for me solve the problem, I think is not the final solution, but it works 鈽猴笍
Hmm... Does anyone know what is the best way to apply configMap with elasticsearch image?
I used a config map with init container that copies the config files from a config map to an empty dir volume, this way it doesn't fail with the write permissions error
spec:
template:
metadata:
labels:
k8s-app: fluentd-logging
version: v1
kubernetes.io/cluster-service: "true"
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
initContainers:
- name: config-fluentd
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c"]
args:
- cp /fluentd/etc2/fluent.conf /fluentd/etc/fluent.conf;
cp /fluentd/etc2/kubernetes.conf /fluentd/etc/kubernetes.conf;
volumeMounts:
- name: config-path
mountPath: /fluentd/etc
- name: config-source
mountPath: /fluentd/etc2
containers:
- name: fluentd
image: fluent/fluentd-kubernetes-daemonset:elasticsearch
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: elasticsearch.default.svc
- name: FLUENT_ELASTICSEARCH_PORT
value: "9200"
- name: FLUENT_ELASTICSEARCH_SCHEME
value: "http"
- name: FLUENT_UID
value: "0"
- name: FLUENT_ELASTICSEARCH_LOGSTASH_PREFIX
value: "fluentd"
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
- name: config-path
mountPath: /fluentd/etc
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
- name: config-source
configMap:
name: fluentd-config
- name: config-path
emptyDir: {}
tried the above recommendation but it fails with:
adduser: uid '0' in use
chown: unknown user fluent
chown: unknown user fluent
sed: /fluentd/etc/fluent.conf: No such file or directory
Any idea of what I'm doing wrong ? using same fluentd-kubernetes-daemonset:elasticsearch image and trying to configure fluentd via a configMap.
passing the following args in the init container:
cp /fluentd/etc2/system.conf /fluentd/etc/system.conf;
cp /fluentd/etc2/containers.input.conf /fluentd/etc/containers.input.conf;
cp /fluentd/etc2/system.input.conf /fluentd/etc/system.input.conf;
cp /fluentd/etc2/forward.input.conf /fluentd/etc/forward.input.conf;
cp /fluentd/etc2/monitoring.conf /fluentd/etc/monitoring.conf;
cp /fluentd/etc2/output.conf /fluentd/etc/output.conf;
I have FLUENT_UID set to "0". Removed it and now I get:
sed: /fluentd/etc/fluent.conf: No such file or directory
it seems that it was expecting fluent.conf to be present. renamed it in my configmap and now works fine.
can you elaborate on what you did @hkailantzis
hey @kurktchiev. just used the example above posted by "itayariel", but in my case, had to name the config as "fluent.conf" inside my configMap. : e.g.
kind: ConfigMap
apiVersion: v1
metadata:
name: fluentd-es-config
namespace: logging
labels:
addonmanager.kubernetes.io/mode: Reconcile
data:
fluent.conf: |-
.....
wouldn't it be an option to keep the configuration for eg. elasticsearch in the container - where the sed command will work - but move the other configs in a folder like
/etc/fluentd/config.d
and reference it than via
@include /etc/fluentd/config.d/*
which is a mount from the config maps?
kind: ConfigMap
apiVersion: v1
metadata:
name: fluentd-es-config
namespace: logging
labels:
addonmanager.kubernetes.io/mode: Reconcile
data:
fluent.conf: |-
@itayariel & @hkailantzis
Am also getting the same error as "hkailantzis" reported ,
sed: /fluentd/etc/fluent.conf: No such file or directory
Even I have created configmap(fluent.conf) on kube-system namespace as well.
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m44s default-scheduler Successfully assigned kube-system/fluentd-5gcgr to
Normal Pulled 2m43s kubelet,
Normal Created 2m43s kubelet,
Normal Started 2m43s kubelet,
Normal Created 2m4s (x4 over 2m43s) kubelet,
Normal Started 2m3s (x4 over 2m43s) kubelet,
Warning BackOff 85s (x9 over 2m41s) kubelet,
Normal Pulled 74s (x5 over 2m43s) kubelet,
Can some one help me to overcome this please...
This issue has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 30 days
I'm running into the same issue as @Madhansudhan . I don't quite understand why.
This issue has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 30 days
Most helpful comment
I used a config map with init container that copies the config files from a config map to an empty dir volume, this way it doesn't fail with the write permissions error
spec: template: metadata: labels: k8s-app: fluentd-logging version: v1 kubernetes.io/cluster-service: "true" spec: tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule initContainers: - name: config-fluentd image: busybox imagePullPolicy: IfNotPresent command: ["/bin/sh","-c"] args: - cp /fluentd/etc2/fluent.conf /fluentd/etc/fluent.conf; cp /fluentd/etc2/kubernetes.conf /fluentd/etc/kubernetes.conf; volumeMounts: - name: config-path mountPath: /fluentd/etc - name: config-source mountPath: /fluentd/etc2 containers: - name: fluentd image: fluent/fluentd-kubernetes-daemonset:elasticsearch env: - name: FLUENT_ELASTICSEARCH_HOST value: elasticsearch.default.svc - name: FLUENT_ELASTICSEARCH_PORT value: "9200" - name: FLUENT_ELASTICSEARCH_SCHEME value: "http" - name: FLUENT_UID value: "0" - name: FLUENT_ELASTICSEARCH_LOGSTASH_PREFIX value: "fluentd" resources: limits: memory: 200Mi requests: cpu: 100m memory: 200Mi volumeMounts: - name: varlog mountPath: /var/log - name: varlibdockercontainers mountPath: /var/lib/docker/containers readOnly: true - name: config-path mountPath: /fluentd/etc terminationGracePeriodSeconds: 30 volumes: - name: varlog hostPath: path: /var/log - name: varlibdockercontainers hostPath: path: /var/lib/docker/containers - name: config-source configMap: name: fluentd-config - name: config-path emptyDir: {}