gpt4 book ai didi

postgresql - Kubernetes 中 postgres 中持久卷的权限问题

转载 作者:行者123 更新时间:2023-12-03 21:16:43 24 4
gpt4 key购买 nike

我知道这个问题已经被反复问过,但没有得到完整的回答。我在使用持久卷的容器中以 root 用户身份运行 postgres。但是在容器中安装似乎存在权限问题。
容器日志

  `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.

fixing permissions on existing directory /data ... ok
initdb: could not create directory "/data/pg_xlog": Permission denied
initdb: removing contents of data directory "/data"`

持久卷和持久卷声明:
kind: PersistentVolume
apiVersion: v1
metadata:
name: store-persistent-volume
labels:
app: pgmaster
namespace: pustakalaya
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/library/pgmaster-data"

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: store-persistent-volume-claim
labels:
app: postgres
namespace: pustakalaya
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 3Gi

和 Pod 文件:
spec:
selector:
matchLabels:
app: pgmaster
replicas: 1
template:
metadata:
labels:
app: pgmaster
spec:
# initContainers:
# - name: chmod-er
# image: busybox:latest
# command: ['sh', '-c' ,'/bin/chmod -R 777 /data && /bin/chown -R 999:999 /data']
containers:
- name: pgmaster
image: becram/olen-elib-db-master:v5.3.0
env:
- name: POSTGRES_DB
value: pustakalaya
- name: POSTGRES_USER
value: pustakalaya_user
- name: POSTGRES_PASSWORD
value: pustakalaya123
- name: PGDATA
value: /data
- name: POSTGRES_BACKUP_DIR
value: /backup
ports:
- containerPort: 5432
volumeMounts:
- mountPath: /data:rw
name: pgmaster-volume
# restartPolicy: Always
volumes:
- name: pgmaster-volume
persistentVolumeClaim:
claimName: store-persistent-volume-claim

最佳答案

我在 Minikube 上遇到了同样的问题。我用手动方法解决了它。由于该文件夹是在运行节点的主机上创建的,因此我通过 ssh 进入了集群。在 Minikube 上,您可以通过以下方式执行此操作:

minikube ssh
接下来,在集群主机上找到文件夹,手动修改权限。
chmod -R 777 /myfolder
chown -R 999:999 /myfolder
在此之后,我再次执行 list 文件,它运行没有问题。
因此,要解决此问题,您需要从集群计算机而不是容器更改权限。

关于postgresql - Kubernetes 中 postgres 中持久卷的权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53741894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com