pgAdmin

Info

FEATURE AVAILABILITY: Available in v5.5.0 and above

Crunchy Postgres for Kubernetes (CPK) allows deploying pgAdmin either alongside or independently of PostgresClusters. This guide covers configuration options for the PGAdmin API, focusing on two primary setups: one pgAdmin instance per PostgresCluster (one-to-one) or one instance accessing all PostgresClusters in a namespace (one-to-many).

Hint

The PGAdmin API currently supports all actively maintained versions of Postgres.

Verify your Installation

To ensure proper setup, verify the presence of the PGAdmin Custom Resource Definition (CRD) in your cluster using the following command:

kubectl get crd \
  --selector postgres-operator.crunchydata.com/control-plane=postgres-operator

NAME                                                 CREATED AT
pgadmins.postgres-operator.crunchydata.com           ...

If the PGAdmins CRD is not present, upgrade to v5.5.0 or later.

Create a PGAdmin Deployment

Now that you have verified your installation, we can walk through an example deployment of the PGAdmin API. The first step is to create a Secret for your pgAdmin user password. The following command will create a Secret that contains the password for an example user (rhino-user):

kubectl create secret generic pgadmin-password-secret \
  -n postgres-operator \
  --from-literal=rhino-user=$RHINO_USER_PASSWORD

Once you have created the password Secret, you're ready to define your PGAdmin deployment. Much like a PostgresCluster, a PGAdmin deployment is defined as YAML:

apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PGAdmin
metadata:
  name: rhino
  namespace: postgres-operator
spec:
  users:
  - username: rhino@example.com
    role: Administrator
    passwordRef:
      name: pgadmin-password-secret
      key: rhino-password
  dataVolumeClaimSpec:
    accessModes:
    - "ReadWriteOnce"
    resources:
      requests:
        storage: 1Gi
  serverGroups:
  - name: supply
    postgresClusterSelector: {}

This YAML defines a PGAdmin named rhino that will discover every PostgresCluster in the postgres-operator namespace.

Create this resource in your Kubernetes environment, typically by saving it as a file and using kubectl apply -f pgadmin.yaml, and CPK will create your pgAdmin deployment.

With your PGAdmin deployment created, you can start a port-forward to the Pod and log into pgAdmin with your user (rhino-user) and password ($RHINO_USER_PASSWORD) at localhost:5050.

Once you are connected to pgAdmin, you can access the PostgresClusters that were discovered. Before you can see your Postgres data, you will need to provide your pguser password. With that you can use your pgAdmin interface to access your Postgres data.

Deleting a PGAdmin

When you are done using this PGAdmin deployment, you can delete the resource by name or by file:

# Delete by name
kubectl delete pgadmin rhino -n postgres-operator
# or Delete by file
kubectl delete -f pgadmin.yaml