# Information about emptyDir and hostPath for persistent volumes

**URL:** <https://forums.percona.com/t/information-about-emptydir-and-hostpath-for-persistent-volumes/13887>\
**Category:** Percona Operator for MySQL\
**Tags:** percona, kubernetes\
**Created:** [January 12, 2022, 5:44pm UTC](https://forums.percona.com/t/information-about-emptydir-and-hostpath-for-persistent-volumes/13887 "2022-01-12T17:44:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phuo](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/phuo/32/5567_2.png) [@phuo](https://forums.percona.com/u/phuo)\
**Post date:** [January 12, 2022, 5:44pm UTC](https://forums.percona.com/t/information-about-emptydir-and-hostpath-for-persistent-volumes/13887/1 "2022-01-12T17:44:11Z")

</div>

Hello,

I’m trying to run the operator from this page : [Install Percona server for MongoDB on Kubernetes](https://www.percona.com/doc/kubernetes-operator-for-psmongodb/kubernetes.html).

Operator seems to be running and it’s trying to create rs and cfg but I have a hard time with the linked persistent volumes. I use molecule to build my cluster so I don’t really want fs to be kept so I tried to uncomment the emptyDir: {} but I don’t understand if I have to put a path or not.

If I do, the operator doesn’t even start because of wrong format.

But If I don’t, my pvc throws this error :  
`failed to provision volume with StorageClass "standard": failed to create volume pvc-1b0d5948-0074-4149-973f-c6bcdb135c66: pods "create-pvc-1b0d5948-0074-4149-973f-c6bcdb135c66" is forbidden: unable to validate against any pod security policy: [spec.volumes[0]: Invalid value: "hostPath": hostPath volumes are not allowed to be used spec.volumes[0]: Invalid value: "hostPath": hostPath volumes are not allowed to be used]`

This is the part I don’t understand because all the hostPath part is still commented.

For the cr.yaml, I used [percona-server-mongodb-operator/cr.yaml at main · percona/percona-server-mongodb-operator · GitHub](https://github.com/percona/percona-server-mongodb-operator/blob/main/deploy/cr.yaml) and just uncomment the emptyDir part.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![phuo](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/phuo/32/5567_2.png) [@phuo](https://forums.percona.com/u/phuo)\
**Post date:** [January 13, 2022, 8:20am UTC](https://forums.percona.com/t/information-about-emptydir-and-hostpath-for-persistent-volumes/13887/2 "2022-01-13T08:20:45Z")

</div>

I found out the answer. It was linked to the PodSecurityPolicy that was added to the cluster. I still don’t understand why the message talks about hostPath but if I looked at the start of the sentence “is forbidden: unable to validate against any pod security policy” since the start I wouldn’t have looked the wrong direction.

---

<div class="post-metadata">

**Author:** ![Edith-Puclla](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/edith-puclla/32/6980_2.png) [@Edith-Puclla](https://forums.percona.com/u/Edith-Puclla)\
**Post date:** [November 16, 2023, 12:45pm UTC](https://forums.percona.com/t/information-about-emptydir-and-hostpath-for-persistent-volumes/13887/3 "2023-11-16T12:45:49Z")

</div>

> [@phuo](#):
>
> emptyDir

Hello, @phuo.Thank you for the update on your situation. I’m glad you’ve identified the root cause of the problem as being linked to the PodSecurityPolicy (PSP) in your cluster.

However, I have not been able to replicate your problem by uncommenting the `emptyDir` part in the  
`volumeSpec` section for `replsets`.

> ```
> volumeSpec:
> emptyDir: {}
> # hostPath:
> # path: /data
> # type: Directory
> persistentVolumeClaim:
> #annotations:
> # volume.beta.kubernetes.io/storage-class: example-hostpath
> # labels:
> rack #: rack-22
> # storageClassName: standard
> # accessModes: ["ReadWriteOnce"]
> 
> ```

Uncommenting the line: `emptyDir: {}`, all resources are displayed correctly in my case.  
If you could tell me more details about what you modified and where it could help clarify your initial problem.  
I also told you some things that helped me better understand the issue of `emptyDir` and `hostpath`.

- `volumes` is a field in the `Pod` specification where you define all storage volumes that the pod can use. These could include `emptyDir`, `persistentVolumeClaim`, `configMap`, etc.

- When you specify `emptyDir: {}` in your Kubernetes pod specification, it means that you’re asking Kubernetes to create a temporary directory on the host machine that’s initially empty. You do not need to provide a **path** for `emptyDir`; it is managed by Kubernetes itself.

- On the other hand, `volumeSpec` is not a standard field in the core Kubernetes Pod or Deployment specifications. It could be a custom field defined by a third-party operator or a Custom Resource Definition (CRD), which you can see in our [deploy/cr.yaml](https://github.com/percona/percona-server-mongodb-operator/blob/main/deploy/cr.yaml) (This was the one I modified to replicate your issue)

I hope we can hear from you, and if you have any more problems deploying the Operator, let us know.

Thank you for your contribution, @phuo !
