Trying to setup a kubernetes cluster and have created a persistent volume thus:
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv-volume
labels:
type: local
app: postgres
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/data/postgres"
where,
/data is a mounted filesystem on minikube startup, say $HOME/data.
A claim binds to the above pv:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pv-claim
labels:
app: postgres
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
The postgres pod is created as follows:
apiVersion: v1
kind: Pod
metadata:
name: postgres
labels:
app: postgres
tier: backend
spec:
hostname: postgres
containers:
- name: postgres
image: postgres:9.5
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
envFrom:
- configMapRef:
name: postgres-config
volumeMounts:
- mountPath: "/var/lib/postgresql/data"
name: postgresdb
volumes:
- name: postgresdb
persistentVolumeClaim:
claimName: postgres-pv-claim
However, the pod/container is never created. It complains:
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.
initdb: could not access directory "/var/lib/postgresql/data": Permission denied
I have tried setting the permissions of the mounted directory to be owned by postgres:postgres but still getting the same error.
Thanks!
Are you using NFS for your persistent volume, how are those permissions set?
By using $HOME/data do you mean you are using the Mounted Host Folders of minikube. From past experience with boot2docker and "Docker for Mac", I would assume it is not possible to chown or chmod the shared folder (or sub folders) as the entrypoint script would try if started normally. You most likely just need to run the postgres container as a different user (ie --user 1000:50 on docker run). You'll need to substitute in the user and group id of the owner of the shared folder as seen from the minikube VM. See the Arbitrary --user notes on the docs on the Docker Hub.
Other notes: The shared folder may not even support what postgres needs to run (like fsync: https://github.com/docker/for-win/issues/445). In this case move to a named volume or a folder on the VM that isn't shared to the host. If the shared folder is owned by root see (https://github.com/docker-library/postgres/issues/558#issuecomment-472234418).
Closing since this is an issue with your environment, for further help you could try asking the Docker Community Forums, the Docker Community Slack, or Stack Overflow.