我正在 kubernetes 上部署 pgadmin 和 postgres。当我查看部署时,我发现有 2 个部署尚未准备好。当我查看 Pgadmin 的日志时,我发现它给出了错误,因为它无法连接到 postgres。我使用 configmap 将 pgadmin 连接到 postgres。当我查看 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 /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
Bus error (core dumped)
child process exited with exit code 135
initdb: removing contents of data directory "/var/lib/postgresql/data"
running bootstrap script ...
yaml 文件:
#configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-configmap
data:
db_url: postgres-service
---
#postgres
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-deployment
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13.3
ports:
- containerPort: 5432
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-password
---
apiVersion: v1
kind: Service
metadata:
name: postgres-service
spec:
selector:
app: postgres
ports:
- protocol: TCP
port: 5432
targetPort: 5432
---
#pgadmin
apiVersion: apps/v1
kind: Deployment
metadata:
name: pgadmin-deployment
labels:
app: pgadmin
spec:
replicas: 1
selector:
matchLabels:
app: pgadmin
template:
metadata:
labels:
app: pgadmin
spec:
containers:
- name: pgadmin
image: dpage/pgadmin4
ports:
- containerPort: 49762
env:
- name: PGADMIN_DEFAULT_EMAIL
value: [email protected]
- name: PGADMIN_DEFAULT_PASSWORD
value: password
- name: PGADMIN_LISTEN_ADDRESS
valueFrom:
configMapKeyRef:
name: postgres-configmap
key: db_url
---
apiVersion: v1
kind: Service
metadata:
name: pgadmin-service
spec:
selector:
app: pgadmin
type: LoadBalancer
ports:
- protocol: TCP
port: 49762
targetPort: 49762
nodePort: 30001
分析评论后,以下资源似乎有助于解决此问题:
总而言之,当 postgres 在容器内运行时编辑
/usr/share/postgresql/postgresql.conf.sample
文件可以通过将自定义 postgresql.conf
放入容器内的临时文件中并在运行时覆盖默认配置(如此处所述)来完成。此外,使用“play with kubernetes”websites保留一个虚拟入口点脚本,然后旋转容器或尝试将文件复制到容器可能会很有用。
我自己遇到问题后,似乎它与
huge_pages
在 sysctl.conf
中的底层操作系统中被激活密切相关。
通过浏览之前的答案,我并不清楚错误与
huge_pages
的关系,因此这是一篇小文章,以使其更清晰并直接总结可能的解决方案。
huge_pages
中的设置 vm.nr_hugepages = 0
禁用操作系统中的 sysctl.conf
,取自此处。请注意,可能需要重新启动才能使更改生效。huge_pages
修改 postgresql 配置来禁用 postgresql 中的 huge_pages = off
,取自此处。如果您在尝试使用 bitnami
图表部署
postgresql时遇到此问题。由于权限问题,无法直接修改
postgresql.conf.sample
。
但是 this github 线程提供了一个示例 helm 配置来让 bitnami 图表工作。
primary:
extendedConfiguration: |-
huge_pages = off
extraVolumeMounts:
- name: pg-sample-config
mountPath: /opt/bitnami/postgresql/share/postgresql.conf.sample
subPath: postgresql.conf.sample
extraVolumes:
- configMap:
name: pg-sample-config
name: pg-sample-config
extraDeploy:
- apiVersion: v1
kind: ConfigMap
metadata:
name: pg-sample-config
data:
postgresql.conf.sample: |-
huge_pages = off