1

I am deploying pgadmin and postgres on kubernetes. When i look at deployments I see that 2 deployments are not ready. When I look at logs of Pgadmin, I see that it gives error as it can not connect to postgres. I use configmap to connect pgadmin to postgres. When I look at logs of postgres I see error.

Logs:

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 file:

#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@email.com
        - 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
Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
name46327
  • 11
  • 1
  • 2

2 Answers2

3

After analysing the comments it looks like below resources have been helpful to solve this problem:

  1. How to customize the configuration file of the official PostgreSQL Docker image?
  2. https://github.com/docker-library/postgres/issues/451#issuecomment-447472044

To sum up, editing /usr/share/postgresql/postgresql.conf.sample file while postgres runs inside a container can be done by putting a custom postgresql.conf in a temporary file inside the container and overwriting the default configuration at runtime as described here. Also, keeping a dummy entry point script using "play with kubernetes" websites and then spinning up the container or trying to copy the file to the container might be useful.

Jakub Siemaszko
  • 668
  • 3
  • 8
1

After having the problem myself it seems that it strongly relates to huge_pages being activated in the underlying OS in sysctl.conf.

The relationship of the error to huge_pages was not clear for me from skimming through the previous answer, hence this is a small write-up to make it clearer and directly summarize possible solutions.

Possible solutions for k8s:

  1. Disable huge_pages in the OS with setting vm.nr_hugepages = 0 in sysctl.conf, taken from here. Please note that a restart might be necessary for the changes to take effect.
  2. Disable huge_pages in postgresql by modifying postgresql config with the option huge_pages = off, taken from here.

Solution for bitnami helm chart:

In case you run into this problem while trying to deploy postgresql with bitnami charts. The postgresql.conf.sample can't be modified directly due to permission problems. But this github thread provides an example helm config to get the bitnami chart working.

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
vinerich
  • 11
  • 1
  • 2