Database

RAIL provide Postgres clusters that you can set up to provide database services for your application. These are provided by the CloudNativePG operator.

Attention

This feature has not been rolled out to the RAIL production clusters yet. It’s currently only available from the RAIL test clusters.

Postgres clusters are by default created with a database called app and a corresponding user called app as well, but in order to connect to it we also need to provide a password for the user. The password is set up with a secret like this one:

apiVersion: v1
kind: Secret
metadata:
  name: db-app-user
type: kubernetes.io/basic-auth
stringData:
  username: app
  password: pass1

and then you can set up the cluster with a reference to this secret with:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: db
spec:
  instances: 2
  bootstrap:
    initdb:
      database: app
      owner: app
      secret:
        name: db-app-user
  storage:
    size: 500Mi

This sets up a service with a name derived from the cluster name, suffixed by -rw (in this case db-rw), that you can connect to. In another Pod in the same namespace where the psql command is available you can connect to the database like this:

$ psql --host=db-rw --username=app
Password for user app:
psql (16.9 (Ubuntu 16.9-0ubuntu0.24.04.1), server 17.0 (Debian 17.0-1.pgdg110+1))
WARNING: psql major version 16, server major version 17.
        Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

app=>

Backup

To be answered…