rowanruseler / helm-charts

Curated applications for Kubernetes
Apache License 2.0
109 stars 121 forks source link

[pgadmin4] Working pgpass example with serverDefinitions #254

Closed kleberbaum closed 3 months ago

kleberbaum commented 4 months ago

Is your feature request related to a problem? Please describe. As a new user of this Helm chart, deploying a working configuration has been challenging. I would greatly appreciate a working pgpass example including serverDefinitions even if it's considered hackish.

It would be helpful to mention the chart and pgAdmin version as well, given the related Issue #193.

Describe the solution you'd like P. S. pgpass solution in examples folder doesn't work by the way. I have a working copy inspired by https://github.com/rowanruseler/helm-charts/issues/72#issuecomment-1002300143 If you think hackish example is useful, I can provide it in a separate PR too.

Originally posted by @ViliusS in https://github.com/rowanruseler/helm-charts/issues/202#issuecomment-1531427929

Additional context My goal is to deploy pgAdmin with pre-configured databases (json) available to all users like #115. I'm open to using older versions of pgAdmin or the chart if needed.

ViliusS commented 4 months ago

In your values.yaml for the chart:

serverDefinitions:
  ## If true, server definitions will be created
  ##
  enabled: true

  ## The resource type to use for deploying server definitions.
  ## Can either be ConfigMap or Secret
  resourceType: ConfigMap

  servers:
    server1:
      Name: "Your Server Name"
      Group: "Your Server Group"
      Host: "postgresql"
      Port: 5432
      Username: "postgres"
      MaintenanceDB: "postgres"
      Shared: true
      ConnectionParameters:
        passfile: "../../file.pgpass"

extraSecretMounts:
  - name: pgpassfile
    secret: pgadmin-pgpassfile-secret
    mountPath: "/tmp/file.pgpass"
    subPath: pgpassfile

## Additional InitContainers to initialize the pod
##
extraInitContainers: |
  - name: prepare-pgpass
    image: busybox:latest
    imagePullPolicy: Always
    command:
      - /bin/sh
      - -c
      - |
        cp /tmp/file.pgpass /var/lib/pgadmin/file.pgpass
        chown 5050:5050 /var/lib/pgadmin/file.pgpass
        chmod 600 /var/lib/pgadmin/file.pgpass
    volumeMounts:
      - name: pgadmin-data
        mountPath: /var/lib/pgadmin
      - name: pgpassfile
        mountPath: /tmp/file.pgpass
        subPath: pgpassfile
    securityContext:
      runAsUser: 0

In Kubernetes secret YAML:

apiVersion: v1
kind: Secret
metadata:
  name: pgadmin-pgpassfile-secret
type: Opaque
stringData:
  pgpassfile: |
    postgresql:5432:*:postgres:postgres

You can add more servers to the list, plus more hostnames to pgpassfile (one hostname per line) if needed.

kleberbaum commented 4 months ago

Thank you very much @ViliusS. What chart and pgAdmin version are you using?

ViliusS commented 4 months ago

I'm using 1.18.x something, but this should work with latest version too.