[Statefulset][postgres] : chmod: changing permissions of '/var/run/postgresql': Operation not permitted chown: changing ownership of '/var/lib/postgresql/data/pgdata': Operation not permitted

Hi all,

Hopefully someone else faced the following issue :fist:
When running a statefulset app with a postgres:11 and PVC , the postgres pod is always crashing with the following error :no_mouth:

chmod: changing permissions of '/var/run/postgresql': Operation not permitted
chown: changing ownership of '/var/lib/postgresql/data/pgdata': Operation not permitted

I already did some research on the web (GitHub and stackoverflow) none of the solution provided works for me (unfortunately) .

Here is my yaml file

spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: postgresql-db
  serviceName: postgresql-db
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: postgresql-db
    spec:
      containers:
      - envFrom:
        - configMapRef:
            name: postgres-configuration
        image: postgres:11
        imagePullPolicy: Always
        name: postgresql-db
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: postgresql-db-disk
        - mountPath: /docker-entrypoint-initdb.d/initdb.sql
          name: psql-initdb-config
          subPath: initdb.sql
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 420
          name: psql-initdb-config
        name: psql-initdb-config
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
  volumeClaimTemplates:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      creationTimestamp: null
      name: postgresql-db-disk
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      storageClassName: localstorage
      volumeMode: Filesystem

and here is my conf.yaml

apiVersion: v1
data:
  PGDATA: /var/lib/postgresql/data/pgdata
  POSTGRES_DB: awesomedb
  POSTGRES_PASSWORD: perfectpassword
  POSTGRES_USER: postgres
kind: ConfigMap
  name: postgres-configuration
  namespace: default

please if anyone has already faced this issue, explain me what is going wrong with mine.

Best,

Another link to this related issue too : chmod: changing permissions of 'var/lib/postgresql/data': Permission denied · Issue #116 · docker-library/postgres · GitHub

The solution did not work for me.

Hello All,

I hope it will help others :

  • :warning: The main problem was : I was running my stateful app in the DEFAULT NAMESPACE

  • :white_check_mark: Solution : After running my app using a different namespace than the default one everything went good.