我通过跟随/var/lib/postgresql/data
与this answer安装initContainers
解决了许可问题。
现在我正在尝试将postgresql.conf
作为一个卷进行安装,而且我遇到了类似的许可问题,它引发了chown: /var/lib/postgresql/data/postgresql.conf: Read-only file system
。
我能错过什么?我尝试了一堆不同的变化而运气不佳。
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: postgres
labels:
app: postgres
spec:
serviceName: postgres
replicas: 1
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: postgres
spec:
terminationGracePeriodSeconds: 10
initContainers:
- name: chmod-er
image: busybox:latest
command:
- /bin/chown
- -R
- '0'
- /var/lib/postgresql/data
volumeMounts:
- name: postgredb
mountPath: /var/lib/postgresql/data
- name: pg-config
mountPath: /var/lib/postgresql/data/postgresql.conf
subPath: postgresql.conf
containers:
- name: postgres
image: mdillon/postgis:10-alpine
ports:
- containerPort: 5432
volumeMounts:
- name: postgredb
mountPath: /var/lib/postgresql/data
subPath: data
- name: pg-config
mountPath: /var/lib/postgresql/data/postgresql.conf
subPath: postgresql.conf
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: postgres-pvc
- name: pg-config
configMap:
name: pg-config
items:
- key: postgresql.conf
path: postgresql.conf
从kubernetes 1.8开始,configmap以只读方式挂载,摘自CHANGELOG-1.8.md:
更改secret,configMap,upwardAPI和预计卷以挂载只读,而不是允许应用程序写入数据然后自动还原。在版本1.11之前,设置要素门ReadOnlyAPIDataVolumes = false将保留旧行为。 (#58720,@ joelsmith)
如果要更改从configmap挂载的文件,可以将其复制到另一个目录,然后进行更新。