gpt4 book ai didi

postgresql - PgAdmin 的 Kubernetes 持久卷挂载

转载 作者:行者123 更新时间:2023-12-02 12:09:42 24 4
gpt4 key购买 nike

我正在尝试为我的 pgadmin 部署创建一个持久卷声明,以便我可以在每次从 CD 管道部署后推出更新时保留我的设置、服务器等。
在我的日志中,我收到以下错误:

...
[2020-10-05 00:54:56 +0000] [91] [INFO] Worker exiting (pid: 91)
WARNING: Failed to set ACL on the directory containing the configuration database:
[Errno 1] Operation not permitted: '/var/lib/pgadmin'
HINT : You may need to manually set the permissions on
/var/lib/pgadmin to allow pgadmin to write to it.
ERROR : Failed to create the directory /var/lib/pgadmin/sessions:
[Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
HINT : Create the directory /var/lib/pgadmin/sessions, ensure it is writeable by
'pgadmin', and try again, or, create a config_local.py file
and override the SESSION_DB_PATH setting per
https://www.pgadmin.org/docs/pgadmin4/4.26/config_py.html
只是一堆写入权限失败:
PGAdmin 部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: pgadmin
spec:
selector:
matchLabels:
app: pgadmin
replicas: 1
template:
metadata:
labels:
app: pgadmin
spec:
containers:
- name: pgadmin4
image: dpage/pgadmin4
volumeMounts:
- mountPath: /var/lib/pgadmin
name: pgadminstorage
env:
- name: PGADMIN_DEFAULT_EMAIL
valueFrom:
secretKeyRef:
name: un
key: un
- name: PGADMIN_DEFAULT_PASSWORD
valueFrom:
secretKeyRef:
name: pw
key: pw
- name: PGADMIN_PORT
value: "80"
ports:
- containerPort: 80
name: pgadminport
volumes:
- name: pgadminstorage
persistentVolumeClaim:
claimName: pgadmin-persistent-volume-claims-cfg
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pgadmin-persistent-volume-claims-cfg
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
我会在这里错过什么?
更新:
这可能是 digitalocean 特有的问题,并且无法设置权限。 PVC 会将 perms 设置为 root,但以 pgadmin 的身份写入会导致启动时出现问题 将此添加到我的 pgadmin 部署中修复了所有问题
      initContainers:
- name: pgadmin-data-permission-fix
image: busybox
command: ["/bin/chown", "-R", "5050:5050", "/var/lib/pgadmin"]
volumeMounts:
- name: pgadminstorage
mountPath: /var/lib/pgadmin
您也可以在目录上递归 chmod 并且也可以。

最佳答案

我已经复制了你的问题。根本原因在于 PgAdmin问题,而不是 Kubernetes。 Pod 将毫无问题地部署。您将收到错误,因为容器将无法在文件夹 /var/lib 内创建文件夹.如果您检查 pgadmin pod 日志 - kubectl logs <pgadmin-pod>你会看到如下错误:

$ kubectl logs pgadmin-d569b67fd-8rnkc
WARNING: Failed to set ACL on the directory containing the configuration database:
[Errno 1] Operation not permitted: '/var/lib/pgadmin'
HINT : You may need to manually set the permissions on
/var/lib/pgadmin to allow pgadmin to write to it.
ERROR : Failed to create the directory /var/lib/pgadmin/sessions:
[Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
HINT : Create the directory /var/lib/pgadmin/sessions, ensure it is writeable by
'pgadmin', and try again, or, create a config_local.py file
and override the SESSION_DB_PATH setting per
https://www.pgadmin.org/docs/pgadmin4/4.26/config_py.html
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
如果您检查 /var/lib/文件夹权限,您将看到您只能 ReadExecute ,因此您将无法在此文件夹中创建任何内容(默认情况下,您将以 pgadmin 用户身份登录)。
drwxr-xr-x    1 root     root          4096 Sep  5 14:01 lib
根据您的需求,您可以通过几种方式解决它。作为最快的解决方法,您只需更改文件夹的路径即可 Write , 喜欢 tmp .
drwxrwxrwt    1 root     root          4096 Oct  5 14:28 tmp
YAML它看起来像:
  containers:
- name: pgadmin4
image: dpage/pgadmin4
volumeMounts:
- mountPath: /var/tmp/pgadmin
name: pgadminstorage
当您检查日志时,不会有任何问题。
$ kubectl logs pgadmin-6bb74cffb8-6q9tr
NOTE: Configuring authentication for SERVER mode.

sudo: setrlimit(RLIMIT_CORE): Operation not permitted
[2020-10-05 14:28:15 +0000] [1] [INFO] Starting gunicorn 19.9.0
[2020-10-05 14:28:15 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
[2020-10-05 14:28:15 +0000] [1] [INFO] Using worker: threads
/usr/local/lib/python3.8/os.py:1023: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
return io.open(fd, *args, **kwargs)
[2020-10-05 14:28:15 +0000] [89] [INFO] Booting worker with pid: 89
user@cloudshell:~/pgadmin (project)$
关于 PgAdmin权限问题 StackOverflow 上已经有几个主题或 Github喜欢:
OSError: [Errno 13] Permission denied: '/var/lib/pgadmin'
pgadmin exit code 3 PermissionError: [Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
[stable/pgadmin] files in /var/lib/pgadmin/sessions crash the pod
简而言之,您可以尝试手动更改权限或使用特定用户。
另外,如果你使用的是Cloud环境,可以考虑使用 CloudSQL ,而不是试图将数据库放入云中。例如 PostgreSQL with GKE 编辑
根据此答案下方的@Ryan 评论,您还可以使用 Init Containers改变 /var/lib/权限。每个 init container必须在下一个开始之前成功完成,并且它在 pod 中的应用程序容器之前运行.

specialized containers that run before app containers in a Pod. Init containers can contain utilities or setup scripts not present in an app image.

关于postgresql - PgAdmin 的 Kubernetes 持久卷挂载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64201305/

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