Podman: Postgresql with pgadmin
This is a quick one.
I needed to replace the sqlite3 database I was working with. sqlite3 is amazing, but has it's limits.
Naturally I turned to postgres:16
$ podman pod create --name postgre-sql -p 9876:80
This creates a pod with an opening for pgadmin on port 9876
$ podman run --pod postgre-sql -e 'PGADMIN_DEFAULT_EMAIL=syouradmin@yourdomain.com' -e 'PGADMIN_DEFAULT_PASSWORD=passWoRd' --name pgadmin -d docker.io/dpage/pgadmin4:latest
This creates a container with pgadmin running in the postgre-sql pod.
Now, create a volume
$ podman volume create postgres-volume
And use that volume when setting up the final container
$ podman run --name mypgdb --pod postgre-sql -d -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=passWoRd -v postgres-volume:/var/lib/postgresql/data:rw,z docker.io/library/postgres:16
Done.
Now, connect to your pgadmin instance on localhost:9876
Add new server
General
- name == mypgdb (or what ever name you gave the database when created)
Connection
Hostname / address == 0.0.0.0
Username == <your user>
Password == <your password>
Connect
You should now be connected to your postgres instance.
The Kube spec:
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-5.1.1
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
app: postgre-sql
name: postgre-sql
spec:
containers:
- env:
- name: PGADMIN_DEFAULT_EMAIL
value: <your.email>@<your.domain>
- name: PGADMIN_DEFAULT_PASSWORD
value: passWoRd
image: docker.io/dpage/pgadmin4:latest
name: pgadmin
ports:
- containerPort: 80
hostPort: 9876
securityContext: {}
volumeMounts:
- mountPath: /var/lib/pgadmin
name: fe79dca434a958057fa493fb87879ccc2fdc3a73167a7940ff8a382f17ef548b-pvc
- args:
- postgres
env:
- name: POSTGRES_PASSWORD
value: passWoRd
- name: POSTGRES_USER
value: admin
image: docker.io/library/postgres:16
name: mypgdb
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgre-sql-volume-pvc
volumes:
- name: fe79dca434a958057fa493fb87879ccc2fdc3a73167a7940ff8a382f17ef548b-pvc
persistentVolumeClaim:
claimName: fe79dca434a958057fa493fb87879ccc2fdc3a73167a7940ff8a382f17ef548b
- name: postgre-sql-volume-pvc
persistentVolumeClaim:
claimName: postgre-sql-volume
What the keen eyed observer might have noticed is that you cant reach the postgres db from localhost... or any other host for that matter. This is by design of course. Add an application container to the pod and the application container has full access to the database. However, this is not what I want so we have to do a minor update to the kube.yaml file.
In the postgres section of the yaml file, under name: mypgdb add
name: mypgdb
ports:
- containerPort: 5432
hostPort: 5432
Save and re run with
$ podman kube play --replace kube.yaml
this exposes the db to my ad-hoc scripts and applications on localhost. Convenient!
anyways.. 'till next time.