On this page
article
Create PostgreSQL Credentials
In this slide we are going to provision a user and password for the database which will be stored in a Kubernetes secret, and configure our sample-pg-app to retrieve the authentication details from that secret.
Create PostgreSQL user
We can declare a new user that will be associated to the database by creating the following .yaml
in apps/services/sample-pg-app/hooks:
Again, make sure the file name you choose ends with .yaml
, for example, database-user.yaml
.
apiVersion: db.movetokube.com/v1alpha1
kind: PostgresUser
metadata:
name: sample-pg-app-auth
namespace: services
spec:
role: sample-user
database: sample-pg-app-db # This references the Postgres CR
secretName: postgres
privileges: OWNER # Can be OWNER/READ/WRITE
Once you’ve pushed your changes, you should see a new postgresuser and a Kubernetes secret:
You can decode the Kubernetes secret by executing
kubectl -n services get secret postgres-sample-pg-app-auth -o go-template='{{range $k,$v := .data}}{{printf "%s: " $k}}{{$v | base64decode}}{{"\n"}}{{end}}'
Last updated 26 Feb 2024, 22:53 +0200 .