A Kubernetes operator to start instances of PostgREST.
There is an available deployment file ready to be used. Install operator and CRD:
kubectl apply -f deployment.yaml
An example CR is found at config/samples/operator_v1_postgrest.yaml
. The CRD included in the deployment file is found at config/crd/bases/operator.postgrest.org_postgrests.yaml
.
Launch CR:
kubectl apply -f config/samples/operator_v1_postgrest.yaml
A PostgREST custom resource's properties are:
schema
: Required. The schema PostgREST will expose.anonRole
: Optional. The role PostgREST will use to authenticate. If specified, it is assumed to already exist and already have the intended permissions on tables. If not specified, will be auto-generated as as<CR name>_postgrest_role
.tables
: Do not set if you already setanonRole
, otherwise required. List of tables within the schema to expose.grants
: Optional. Ignored if you already setanonRole
. Comma-separated string listing actions permitted on tables. Defaults toSELECT
if not specified. A "full" string isINSERT, SELECT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER
, but you may also useALL
.connection
: Required. A structure to indicate the database to connect to. Its sub-properties are:host
: Optional. Must be provided ifsecretName
is unspecified or the secret does not containPOSTGREST_URL
.port
: Optional.database
: Optional. Must be provided ifsecretName
is unspecified or the secret does not containPOSTGREST_URL
.user
: Used withpassword
to initialize PostgREST. Do not provide ifsecretName
is provided.password
: Used withuser
to initialize PostgREST. Do not provide ifsecretName
is provided.extraParams
: Optional. String for extra connection parameters, in the formatparameter1=value¶meter2=value
.secretName
: Name of a Kubernetes secret containing connection properties. Do not provide ifuser
andpassword
are provided. More information in a later section.
Note that you must provide either secretName
, or user
and password
, but if you provide the former, do not provide the latter two, and vice versa.
Note that the user you provide must have permissions to handle roles in the database.
Instead of writing user and password as properties, you can provide a connection.secretName
property, containing a string with the name of a Kubernetes secret to use to authenticate.
Here is a sample file you can apply with kubectl apply -f secret-file.yml
to create the secret:
apiVersion: v1
kind: Secret
metadata:
name: mysecret
namespace: postgrest-operator-system
stringData:
POSTGRES_URL: postgresql://postgres:postgres@192.168.123.123:5432/postgres?sslmode=disable
USER: postgres # Only required if POSTGRES_URL is not provided
PASSWORD: postgres # Only required if POSTGRES_URL is not provided
If you omit POSTGRES_URL
, then USER
and PASSWORD
are required, but if you provide it, they will be ignored.
POSTGRES_URL
uses the format:
postgresql://user:password@host:port/database?parameter1=value¶meter2=value
A valid sample spec configuration is:
...
spec:
schema: operator
anonRole: anon
connection:
host: 192.168.123.123
database: postgres
user: postgres
password: postgres
Another valid sample (the secret contains POSTGRES_URL
):
...
spec:
schema: operator
tables:
- test
grants: SELECT, UPDATE, INSERT, DELETE
connection:
secretName: mysecret
Another valid sample (the secret contains USER
and PASSWORD
):
...
spec:
schema: operator
tables:
- test
grants: SELECT, UPDATE, INSERT, DELETE
connection:
host: 192.168.123.123
database: postgres
secretName: mysecret