4

I know this question has been asked repeatedly but not fully answered. I have a postgres running in as root user in a container which is using the persistent volume. But it seems like there is permission issue issue in mounting in the container. Container logs

  `The files belonging to this database system will be owned by user
"postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /data ... ok
initdb: could not create directory "/data/pg_xlog": Permission denied
initdb: removing contents of data directory "/data"`

Persistent Volume and Persistent Volume Claim:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: store-persistent-volume
  labels:
    app: pgmaster
  namespace: pustakalaya
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/library/pgmaster-data"

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: store-persistent-volume-claim
  labels:
    app: postgres
  namespace: pustakalaya
spec:
  storageClassName: manual
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 3Gi

and Pod file:

spec:
  selector:
    matchLabels:
      app: pgmaster
  replicas: 1
  template:
    metadata:
      labels:
        app: pgmaster
    spec:
     # initContainers:
     #   - name: chmod-er
     #     image: busybox:latest
     #     command: ['sh', '-c' ,'/bin/chmod -R 777 /data && /bin/chown -R 999:999 /data']
      containers:
        - name: pgmaster
          image: becram/olen-elib-db-master:v5.3.0
          env:
            - name: POSTGRES_DB
              value: pustakalaya
            - name: POSTGRES_USER
              value: pustakalaya_user
            - name: POSTGRES_PASSWORD
              value: pustakalaya123
            - name: PGDATA
              value: /data
            - name: POSTGRES_BACKUP_DIR
              value: /backup
          ports:
            - containerPort: 5432
          volumeMounts:
          - mountPath: /data:rw
            name: pgmaster-volume
#      restartPolicy: Always
      volumes:
       - name: pgmaster-volume
         persistentVolumeClaim:
           claimName: store-persistent-volume-claim
4
  • I believe that root of your issue is in following: In postgres, even when you start it as a root user, process still drops root permission and runs as "postgres" user. So, try to ensure that postgres user has permissions to write in /data directory. Hope it helps. Commented Dec 13, 2018 at 11:59
  • @getslaf sorry I missed a important information. The volume I am using is synced directory in vagrant and the problem seems to be different than I thought. This works fine if I persist data in guest VM itself except the synced folder. Commented Dec 16, 2018 at 4:51
  • I was facing the same issue, and according to the suggestion, I provided the permission like command: ["/bin/sh", "-c", "chmod -R 777 /data"]. But after that, container is not showing any logs and not getting started. Commented May 15, 2019 at 6:59
  • 1
    Did you solve this at the end? I am facing the same issue, any help would be appreciated. Thanks Commented Jan 26, 2021 at 9:52

1 Answer 1

1

I was having the same issue with Minikube. I solved it with a manual approach. Since the folder is created on the host machine - which is running the node, I ssh-ed into the cluster. On Minikube you could do this by:

minikube ssh

Next, find the folder on the cluster host machine and manually change the permissions.

chmod -R 777 /myfolder
chown -R 999:999 /myfolder

After this, I executed the manifest files again, and it ran without a problem. So to fix this, you need to change permissions from your cluster machine and not from your container.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.