PgAdmin 的 Kubernetes 持久卷挂载

Rya*_*yan 6 postgresql pgadmin kubernetes

我正在尝试为我的 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
Run Code Online (Sandbox Code Playgroud)

只是一堆写入权限失败:

PG管理员部署

...
[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
Run Code Online (Sandbox Code Playgroud)

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pgadmin-persistent-volume-claims-cfg
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
Run Code Online (Sandbox Code Playgroud)

我在这里可能会缺少什么?

更新:

这可能是 digitalocean 特有的问题,无法设置权限。PVC 会将权限设置为 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
Run Code Online (Sandbox Code Playgroud)

您也可以在目录上递归 chmod ,也可以。

Pjo*_*erS 5

我已经复制了你的问题。根本原因是PgAdmin问题,而不是 Kubernetes。Pod 将毫无问题地部署。您将收到错误,因为容器无法在文件夹内创建文件夹/var/lib。如果您检查pgadminPod 日志 -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
Run Code Online (Sandbox Code Playgroud)

如果您检查/var/lib/文件夹权限,您将发现您只能ReadExecute,因此您将无法在此文件夹中创建任何内容(默认情况下,您将以pgadmin用户身份登录)。

drwxr-xr-x    1 root     root          4096 Sep  5 14:01 lib
Run Code Online (Sandbox Code Playgroud)

根据您的需求,您可以通过多种方式解决。作为最快的解决方法,您只需更改允许的文件夹路径Write,例如tmp.

drwxrwxrwt    1 root     root          4096 Oct  5 14:28 tmp
Run Code Online (Sandbox Code Playgroud)

YAML看起来像:

  containers:
    - name: pgadmin4
      image: dpage/pgadmin4
      volumeMounts:
        - mountPath: /var/tmp/pgadmin
          name: pgadminstorage
Run Code Online (Sandbox Code Playgroud)

当您检查日志时,不会有任何问题。

$ 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)$
Run Code Online (Sandbox Code Playgroud)

关于PgAdmin权限问题,已经有一些主题StackOverflowGithubOSError : [Errno 13] Permission returned: '/var/lib/pgadmin'

pgadmin 退出代码 3 PermissionError: [Errno 13] 权限被拒绝: '/var/lib/pgadmin/sessions'

/var/lib/pgadmin/sessions 中的 [stable/pgadmin] 文件使 pod 崩溃

简而言之,您可以尝试手动更改权限或使用特定用户。

另外,如果您使用的是云环境,您可以考虑使用CloudSQL,而不是尝试将数据库放入云中。例如PostgreSQL with GKE

编辑

根据此答案下面的 @Ryan 评论,您还可以使用Init Containers来更改/var/lib/权限。每一个都init container必须在下一个开始之前成功完成,并且它在pod.

在 Pod 中的应用程序容器之前运行的专用容器。初始化容器可以包含应用程序映像中不存在的实用程序或设置脚本。