Last active
May 19, 2023 12:46
-
-
Save fk128/249cd7a22c10aad1ebd5981c18d044b0 to your computer and use it in GitHub Desktop.
k8s deployment of pgadmin with server setup from env variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
labels: | |
app: pgadmin | |
name: pgadmin | |
spec: | |
ports: | |
- name: pgadmin | |
port: 80 | |
targetPort: 80 | |
selector: | |
app: pgadmin | |
type: NodePort | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: pgadmin | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: pgadmin | |
template: | |
metadata: | |
labels: | |
app: pgadmin | |
spec: | |
initContainers: | |
- name: server-setup | |
image: busybox | |
command: ["sh", "-c"] | |
args: | |
- | | |
# pgpass file is relative to user storage | |
echo '{"Servers":{"1":{"Name":"db", "Group": "Servers","Host":"'"${POSTGRES_SERVER}"'","Port":5432,"MaintenanceDB":"postgres","Username":"postgres","PassFile":"../../../../../pgpass","SSLMode":"prefer"}}}' >/data/servers.json | |
echo ${POSTGRES_SERVER}:5432:*:postgres:${POSTGRES_PASSWORD} > /data/pgpass | |
chmod 0600 /data/pgpass | |
chown 5050:5050 /data/pgpass | |
volumeMounts: | |
- name: config-volume | |
mountPath: /data/ | |
env: | |
- name: POSTGRES_SERVER | |
valueFrom: | |
secretKeyRef: | |
key: host | |
name: my-secret-rds | |
- name: POSTGRES_PASSWORD | |
valueFrom: | |
secretKeyRef: | |
key: password | |
name: my-secret-rds | |
- name: POSTGRES_DB | |
value: postgres | |
containers: | |
- env: | |
- name: PGADMIN_DEFAULT_EMAIL | |
value: [email protected] | |
- name: PGADMIN_DEFAULT_PASSWORD | |
value: mypass | |
- name: PGADMIN_PORT | |
value: "80" | |
image: dpage/pgadmin4:latest | |
imagePullPolicy: IfNotPresent | |
name: pgadmin | |
ports: | |
- containerPort: 80 | |
resources: | |
limits: | |
memory: 4096Mi | |
volumeMounts: | |
- mountPath: "/pgadmin4/servers.json" | |
subPath: "servers.json" | |
name: config-volume | |
readOnly: true | |
- mountPath: "/pgpass" | |
subPath: "pgpass" | |
name: config-volume | |
readOnly: true | |
volumes: | |
- name: config-volume | |
emptyDir: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment