Christian Bargmann

M.A. student in computer science. Living and working in Hamburg, Germany. Programming addicted. Loves coffee! 🍵❤️⚓

github twitter telegram email
pgweb client for PostgreSQL databases on Kubernetes
Nov 9, 2018
2 minutes read

pgweb client for PostgreSQL databases on Kubernetes

Sometimes it can be helpful to have a graphical interface to manage your database. Whenever I use Postgres, I use pgweb as a client. In one project we ran a Postgres database cluster on Kubernetes and pgweb should be installed as frontend. Unfortunately, the Kubernetes deployment wasn’t as easy as I thought.

About pgweb

Pgweb is a web-based database browser for PostgreSQL, written in Go and works on OSX, Linux and Windows machines. Main idea behind using Go for backend development is to utilize ability of the compiler to produce zero-dependency binaries for multiple platforms. Pgweb was created as an attempt to build very simple and portable application to work with local or remote PostgreSQL databases.

For more information please have a look at the official project repository on Github.

Deploy pgweb on Kubernetes

There is already an official docker image for pgweb. Unfortunately the pgweb binary in the container uses a different network interface than needed. For this reason we need to build our own Docker image for our Kubernetes deployment.

FROM alpine:latest as build
ADD  ./
RUN apk add unzip && unzip

FROM alpine:latest
COPY --from=build ./ ./app
CMD [ "./app/pgweb_linux_amd64", "--sessions" ,"--bind=", "--listen=8080" ]

The arguments can, of course, be adjusted as desired. For Kubernetes it is important that pgweb binds to and not localhost. The image can then be pushed into a docker registry.

The Kubernetes deployment file looks like this:

apiVersion: apps/v1
kind: Deployment
  name: pgweb
    service: pgweb
      service: pgweb
        service: pgweb
        - name: pgweb
          image: your/pgwebimage:latest # Change to your image name
          imagePullPolicy: Always
            - containerPort: 8080
          - name: DATABASE_URL
            value: postgres:            # Add your postgres connection string
apiVersion: v1
kind: Service
  name: pgweb-svc
  type: ClusterIP
  - port: 8080
    protocol: TCP
    targetPort: 8080
    app: pgweb

Then you can access pgweb either via kubectl proxy or kubectl port-forward. Of course you can create an ingress object as well to access pgweb from outside the cluster.

Back to posts