Skip to content

Issue with PostgreSQL Deployment on AWS EFS: Permissions Error on Second Deployment

0

Hello,

I’m facing an issue while deploying PostgreSQL in multiple namespaces on AWS EFS, which is being used as part of our SaaS (Software as a Service) application infrastructure. We chose AWS EFS because of its ability to provide scalable, persistent, and shared storage across multiple instances, which is essential for our application’s architecture.

Here’s the situation:

Initial Deployment (First Time): When I deploy PostgreSQL for the first time in the namespace, everything works correctly. The Persistent Volumes (PV) and Persistent Volume Claims (PVC) are created properly, and there are no issues.

Second Deployment (Subsequent Deployments): For subsequent deployments, I always run into the CrashLoopBackOff error. The logs show the following error:

fixing permissions on existing directory /bitnami/postgresql/data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 20 selecting default shared_buffers ... 400kB selecting default time zone ... Etc/UTC creating configuration files ... ok 2025-03-25 10:57:32.317 UTC [103] FATAL: data directory "/bitnami/postgresql/data" has wrong ownership 2025-03-25 10:57:32.317 UTC [103] HINT: The server must be started by the user that owns the data directory. child process exited with exit code 1 initdb: removing contents of data directory "/bitnami/postgresql/data" running bootstrap script ...

I've ensured that the securityContext with fsGroup: 1001 is added to the deployment configuration.

I checked the ownership and permissions of the /bitnami/postgresql/data directory in the EFS volume, but it seems that the PostgreSQL container is still unable to start due to ownership issues.

Questions:

  • Is there something I am missing regarding the file system permissions for EFS in a multi-namespace setup?

  • What are the best practices for ensuring proper ownership when using EFS with PostgreSQL containers in Kubernetes?

  • How can I avoid this error and successfully deploy PostgreSQL in multiple namespaces on EFS?

1 Answer
1

Did you use an access point on EFS or directly reference the EFS file system without an access point in your PersistentVolume definition?

In my case, when I directly bound the EFS volume in the dev namespace, it worked fine. However, when deploying the same configuration in the test namespace, I encountered the following error: chown: changing ownership of '/bitnami/postgresql/data': Operation not permitted

To resolve this, I created an access point on AWS EFS, and then I updated the volumeHandle in the Persistent Volume definition to explicitly include the EFS access point, like this:

volumeHandle: <fs-id>::<fsap-id>

This allowed the PostgreSQL container to initialize and operate successfully across multiple namespaces.

Here is my pv.yml: Enter image description here

answered a year ago

  • Thanks for sharing ismail

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.