I'm trying to deploy postgres using Kubernetes. This step works well.
But now I need to customised the pg_hba.conf
file. So the idea is to use a configMap to mount the personal file.
Here are my deployment file:
apiVersion: v1
kind: ConfigMap
metadata:
name: pg-hba-configmap
data:
pg_hba.conf: |+
# TYPE DATABASE USER ADDRESS METHOD
# Some personal settings here
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: db
spec:
selector:
matchLabels:
app: db
serviceName: db
replicas: 1
template:
metadata:
labels:
app: db
spec:
nodeSelector:
db: 'true'
containers:
- name: db
image: kartoza/postgis:10.0-2.4
volumeMounts:
- name: data-volume
mountPath: /var/lib/postgresql
- name: pg-hba-config-volume
mountPath: /var/lib/postgresql/10/main/pg_hba.conf
subPath: pg_hba.conf
volumes:
- name: data-volume
hostPath:
path: /data/db
- name: pg-hba-config-volume
configMap:
name: pg-hba-configmap
But this doesn't work. The db is in Error state. In logs, I can see this:
chown: changing ownership of '/var/lib/postgresql/10/main/pg_hba.conf': Read-only file system
Also, on the server where is mounted the database, I only have this:
root@server:/data/db/10/main# ls -l
total 0
-rwxr-xr-x 1 root root 0 Oct 8 08:49 pg_hba.conf
I should have all the database here. It's like if all the folder was overwritten.
What am I doing wrong here and how can I mount my customised config ?
Thanks