Search code examples
dockerkubernetesminikubefluentd

Copying a Fluentd-config file to a kubernetes pod


I've got a fluentd.conf file and I'm trying to use (copy) it in my minikube cluster (works fine in a docker container). The steps are the following:

  1. Ill build (in my minikube docker-env) the docker image with the following commands Dockerfile:
FROM fluent/fluentd:v1.11-1

# Use root account to use apk
USER root

# below RUN includes plugin as examples elasticsearch is not required
# you may customize including plugins as you wish
RUN apk add --no-cache --update --virtual .build-deps \
    sudo build-base ruby-dev \
    && sudo gem install fluent-plugin-elasticsearch \
    && sudo gem sources --clear-all \
    && apk del .build-deps \
    && rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem

COPY conf/fluent.conf /fluentd/etc/
USER fluent

  1. This executes succesfully (so the copy works) and results in a runnable image, the following step is to launch the pods. Part of the deployment files
      spec:
        containers:
        - image: fluentd
          imagePullPolicy: ""
          name: fluentd
          ports:
          - containerPort: 24224
          - containerPort: 24224
            protocol: UDP
          resources: {}
          volumeMounts:
          - mountPath: /fluentd/etc
            name: fluentd-claim0
        restartPolicy: Always
        serviceAccountName: ""
        volumes:
        - name: fluentd-claim0
          persistentVolumeClaim:
            claimName: fluentd-claim0

Everything launches fine but the fluentd-pod returns the following error: No such file or directory @ rb_sysopen - /fluentd/etc/fluent.conf

Anybody got an idea what i'm missing or what i'm doing wrong?

Thanks in advance,


Solution

  • This happens because you are mounting a volume in the same folder.

    Inside your image, the config file is placed in /fluentd/etc/fluent.conf.

    In your pod, you mount the fluentd-claim0 volume into /fluentd/etc/:

    volumeMounts:
    - mountPath: /fluentd/etc
      name: fluentd-claim0
    

    Like it would happen if you mount a volume in a nonempty directory in linux, all files present in the mount point directory will be hidden by the mount itself.

    In order to "fix" this, you could use the subPath option of the volumeMounts entry like described in the documentation. For example:

    volumeMounts:
    - mountPath: /fluentd/etc/myfileordirectory
      name: fluentd-claim0
      subPath: myfileordirectory
    

    This way only myfileordirectory will be mounted in /fluentd/etc/ and the rest of files will still be visible.

    The limitation of this approach is that you need to know the list of files within your volume in advance. If this is not possible, the only alternative is to use a different directory for either your config file or your mountPath.