# Mount volume to rs0 statefulset in percona operator in kubernetes

**URL:** <https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410>\
**Category:** Percona Operator for MongoDB\
**Created:** [July 3, 2022, 7:00am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410 "2022-07-03T07:00:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![namaaker11](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/namaaker11/32/6878_2.png) [@namaaker11](https://forums.percona.com/u/namaaker11)\
**Post date:** [July 3, 2022, 7:00am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/1 "2022-07-03T07:00:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [July 4, 2022, 8:48am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/2 "2022-07-04T08:48:26Z")

</div>

Hey @namaaker11 ,

why do you need this?

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

---

<div class="post-metadata">

**Author:** ![namaaker11](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/namaaker11/32/6878_2.png) [@namaaker11](https://forums.percona.com/u/namaaker11)\
**Post date:** [July 4, 2022, 9:24am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/3 "2022-07-04T09:24:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [July 4, 2022, 10:22am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/4 "2022-07-04T10:22:17Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![namaaker11](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/namaaker11/32/6878_2.png) [@namaaker11](https://forums.percona.com/u/namaaker11)\
**Post date:** [July 4, 2022, 11:00am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/5 "2022-07-04T11:00:06Z")

</div>

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

```auto
 filebeat.inputs:

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

    output.logstash:
      hosts: '${LOGSTASH_URL}'

```

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

```auto
      auditLog:
        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).

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [July 4, 2022, 1:06pm UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/6 "2022-07-04T13:06:35Z")

</div>

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:

```auto
    sidecars:
    - image: ...
      command: ...
      args: ...
      name: rs-sidecar-1
      volumeMounts:
        - mountPath: /mytmp
          name: mongod-data

```

---

<div class="post-metadata">

**Author:** ![namaaker11](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/namaaker11/32/6878_2.png) [@namaaker11](https://forums.percona.com/u/namaaker11)\
**Post date:** [July 5, 2022, 9:23am UTC](https://forums.percona.com/t/mount-volume-to-rs0-statefulset-in-percona-operator-in-kubernetes/16410/7 "2022-07-05T09:23:43Z")

</div>

Thank U so much for you help, this worked 🙂
