[英]postgres on kubernetes volume permission error
I'm trying to deploy postgres/postgis on GKE, but I continue to get the permission error: initdb: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
.我正在尝试在 GKE 上部署 postgres/postgis,但我继续收到权限错误:
initdb: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
。 I've tried various fixes that I've researched but I've yet to get passed this error.我已经尝试了我研究过的各种修复,但我还没有通过这个错误。 Below is my deployment yaml.
下面是我的部署 yaml。
What am I missing?我错过了什么?
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
terminationGracePeriodSeconds: 10
securityContext:
runAsUser: 1000
fsGroup: 1000
containers:
- name: postgres
image: mdillon/postgis:10
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: "database"
- name: POSTGRES_USER
value: "postgres"
- name: POSTGRES_PASSWORD
value: "postgres"
volumeMounts:
- name: postgredb
mountPath: /var/lib/postgresql/data
subPath: data
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: postgres-pvc
虽然不是完全相同的问题,但是这个“使用initContainer:
到chmod
”的答案会让您感兴趣: chown:更改'/ data / db'的所有权:不允许操作
The clue can be found under the PGDATA section:线索可以在 PGDATA 部分下找到:
https://hub.docker.com/_/postgres https://hub.docker.com/_/postgres
This optional variable can be used to define another location - like a subdirectory - for the database files.
此可选变量可用于为数据库文件定义另一个位置(如子目录)。 The default is /var/lib/postgresql/data.
默认为 /var/lib/postgresql/data。 If the data volume you're using is a filesystem mountpoint (like with GCE persistent disks) or remote folder that cannot be chowned to the postgres user (like some NFS mounts), Postgres initdb recommends a subdirectory be created to contain the data.
如果您使用的数据卷是文件系统挂载点(如 GCE 永久磁盘)或无法被 postgres 用户使用的远程文件夹(如某些 NFS 挂载),则 Postgres initdb 建议创建一个子目录来包含数据。
For example:
例如:
$ docker run -d
$ docker run -d
--name some-postgres--name some-postgres
-e POSTGRES_PASSWORD=mysecretpassword-e POSTGRES_PASSWORD=mysecretpassword
-e PGDATA=/var/lib/postgresql/data/pgdata-e PGDATA=/var/lib/postgresql/data/pgdata
-v /custom/mount:/var/lib/postgresql/data-v /custom/mount:/var/lib/postgresql/data
postgres邮局
So you would need 2 items in the YAML to get the equivalent of the Docker command above:因此,您需要 YAML 中的 2 个项目才能获得上述 Docker 命令的等效项:
Mount the PVC to the default directory used by Postgres (which you already have in you YAML)将 PVC 挂载到 Postgres 使用的默认目录(您已经在 YAML 中)
volumeMounts: - name: <volume_name> mountPath: /var/lib/postgresql/data readOnly: false
Add PGDATA variable to the env variables:将 PGDATA 变量添加到 env 变量中:
env: - name: PGDATA value: /var/lib/postgresql/data/pgdata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.