Mount volume to rs0 statefulset in percona operator in kubernetes

I want to add Filebeat container to the rs0 StatefulSet to collect the logs of my mongoDB. I added a filebeat sidecar container to the operator (according to the docs), and now I’m stuck. How can I create an emptyDir volume that would be mounted and accessible on both the mongod container and the filebeat container?

I managed to mount an emptydir volume to the sidecar container, but how can I mount the same volume to the mongod container as well?

1 Like

Hey @namaaker11 ,

why do you need this?

Firebeat container should read the logs from the storage (or stdout) and ship them somewhere.

1 Like

I need to work with log files to keep my system configuration consistent

1 Like

@namaaker11 could you please share how you see it all working through the empty dir? Maybe just a small diagram.

I’m not sure I understand the overall design. If there is a missing piece in our Operator - would be glad to improve it.

1 Like

Sure! thank you for you time and attention :slight_smile:
I would like to add a filebeat container to cr.yaml, that works with this configuration:


      - type: log
          - /var/log/psmdb/.*
        json.fields_under_root: true
        json.add_error_key: true
        encoding: utf-8

      hosts: '${LOGSTASH_URL}'

And also enable the auditing option in the operator, with this configuration:

        destination: file
        format: JSON
        path: /var/log/psmdb/audit.json
        filter: '{}'

In order for that to work, I need to create a volume (preferably emptyDir) and mount it in both the filebeat container and the mongod container on /var/log/psmdb. mongod will write the audit log into the volume, and filebeat will send the logs to elasticsearch.

I know filebeat can pull containers stdout, but in that case I will get all the logs from all the containers in my node, and all I need are the audit logs from my percona mongoDB cluster.

I would be glad to hear if you have other suggestions how to ship the mongoDB audit logs to elastic (or even how to ship the audit logs to a sidecar container).

1 Like

It is not possible to have two volumes in a main container (mongod).

You can stream the logs to the existing volume of a Replica Set node container and read from the same volume from a sidecar (as containers in the Pod share volumes).

Like you can save logs to /data/db.
And have something like this in a sidecar config:

    - image: ...
      command: ...
      args: ...
      name: rs-sidecar-1
        - mountPath: /mytmp
          name: mongod-data

Thank U so much for you help, this worked :slight_smile:

1 Like