Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass postgres parameter into Kubernetes deployment

I am trying to set a postgres parameter (shared_buffers) into my postgres database pod. I am trying to set an init container to set the db variable, but it is not working because the init container runs as the root user.

What is the best way to edit the db variable on the pods? I do not have the ability to make the change within the image, because the variable needs to be different for different instances. If it helps, the command I need to run is a "postgres -c" command.

"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.
like image 805
mmiara Avatar asked Aug 05 '26 15:08

mmiara


1 Answers

In my case, the @Rico answer didn't help me out of the box because I don't use postgres with a persistent storage mount, which means there is no /var/lib/postgresql/data folder and pre-existed database (so both proposed options have failed in my case).

To successfully apply postgres settings, I used only args (without command section).

In that case, k8s will pass these args to the default entrypoint defined in the docker image (docs), and as for postgres entrypoint, it is made so that any options passed to the docker command will be passed along to the postgres server daemon (look section Database Configuration at: https://hub.docker.com/_/postgres)

apiVersion: v1
kind: Pod
metadata:
  name: postgres
spec:
  containers:
    - image: postgres:9.6.8
      name: postgres
      args: ["-c", "shared_buffers=256MB", "-c", "max_connections=207"]

To check that the settings applied:

$ kubectl exec -it postgres -- bash
root@postgres:/# su postgres
$ psql -c 'show max_connections;'
 max_connections
-----------------
 207
(1 row)
like image 192
ujlbu4 Avatar answered Aug 07 '26 06:08

ujlbu4