<p>I have a yaml file that creates a namespace, a persistent volume, a persistent volume claim and a statefulset that uses the pvc. When I run this file with <code>kubectl apply -f myfile.yaml</code>, I don't get any errors.</p>

<pre><code>apiVersion: v1
kind: Namespace
metadata:
  name: mynamespace

---

apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: mynamespace
  name: postgres-pv
  labels:
    name: postgres-volume 
spec:
  storageClassName: manual # same storage class as pvc
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: 10.0.0.11 # ip addres of nfs server
    path: "/mnt/kubernetes-nfs-volume/customer1/postgres" # path to directory

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: mynamespace
  name: postgres-pvc
  labels:
    name: postgres-volume 
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany #  must be the same as PersistentVolume
  resources:
    requests:
      storage: 5Gi

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-configuration
  namespace: mynamespace
  labels:
    app: postgres
data:
  POSTGRES_DB: databasename
  POSTGRES_USER: mydatabaseuser
  POSTGRES_PASSWORD: mysupersecretpassword

---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: mynamespace
  name: postgres-statefulset
  labels:
    app: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:13
        envFrom:
        - configMapRef:
            name: postgres-configuration
        ports:
        - containerPort: 5432
          name: postgresdb
        volumeMounts:
        - name: pv-data
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: pv-data
        persistentVolumeClaim:
          claimName: postgres-pvc

---

apiVersion: v1
kind: Service
metadata:
  namespace: mynamespace
  name: postgres
  labels:
    app: postgres
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: postgres
</code></pre>

<p>Next, when I run <code>kubectl describe -n mynamespace postgres-statefulset</code>, I get the following output: </p>

<p><a href="https://i.stack.imgur.com/Ez5b1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ez5b1.png" alt="enter image description here"></a></p>

<p>Looks good so far! However, running <code>kubectl get statefulset -n mynamespace</code> returns this: </p>

<p><a href="https://i.stack.imgur.com/L80Sf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L80Sf.png" alt="enter image description here"></a></p>

<p>What am I doing wrong? Also, the PV and PVC have been set up correctly, as I can use them with an nginx deployment for testing purposes succesfully. I have deleted everything in my cluster before running this script.</p>

<p>The output of <code>kubectl get events -n mynamespace</code> is as follows: </p>

<p><a href="https://i.stack.imgur.com/KH4P5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KH4P5.png" alt="enter image description here"></a></p>

yesman
<p>Found it out myself. On the fileserver with the NFS disk, I had to update <code>/etc/exports</code> to include <code>no_root_squash</code> on the folder that the postgres container uses as a mount. I figured this out by checking the logs of the pod, which had the error message <code>chown: changing ownership of ‘/var/lib/postgresql/data’: Operation not permitted</code> and googling that error. </p>
