Failed starting postgres DB container via k8s on linux

When starting a postgres DB container via kubernetes on linux host server, it failed to start the container.

1
2
3
[root@compute2 log]# kubectl get pod
NAME READY STATUS RESTARTS AGE
test-764dc8f84b-smg92 0/1 Error 3 49s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@compute2 log]# kubectl logs test-764dc8f84b-smg92
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 default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
child process was terminated by signal 7
initdb: removing contents of data directory "/var/lib/postgresql/data"

Image is with no problem cuz I can do docker run to start container successfully.
————————————— Solution —————————————
https://github.com/docker-library/postgres/issues/451
there are several possible solutions to the problem:

  1. Modify the docker image to be able to set huge_pages = off in /usr/share/postgresql/postgresql.conf.sample before initdb was ran (this is what I did).
  2. Turn off huge page support on the system (vm.nr_hugepages = 0 in /etc/sysctl.conf).
  3. Fix Postgres’s fallback mechanism when huge_pages = try is set (the default).
  4. Modify the k8s manifest to enable huge page support (https://kubernetes.io/docs/tasks/manage-hugepages/scheduling-hugepages/).
  5. Modify k8s to show that huge pages are not supported on the system, when they are not enabled for a specific container.

I tried the second way, and solve the issue successfully.