Skip to content

Commit 846f11e

Browse files
committed
Add docs about dbinstances
Signed-off-by: Nikolai Rodionov <allanger@badhouseplants.net>
1 parent bda2e62 commit 846f11e

4 files changed

Lines changed: 161 additions & 8 deletions

File tree

docs/database.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,36 @@ USER: << base64 encoded user name (generated by db operator) >>
227227

228228
Then DB Operator will connect to an existing database and set up a user for it.
229229

230-
## Experimantal features
231-
232-
Experimantal features are added via annotations, the following features are available for `Databases`
230+
## Experimental features
233231

232+
Experimental features are added via annotations, the following features are available for `Databases`
234233

234+
---
235235
This annotation should be used, when a DbUser is not allowed to log in with password, should be used on the RDS instances, when the SSO is used for authentication.
236236

237237
For more info see this issue: https://github.com/db-operator/db-operator/issues/125
238238
```yaml
239239
kinda.rocks/rds-iam-impersonate: "true"
240240
```
241-
242-
Delete a postgres database with present connectins, might be useful when pgbouncer is used
241+
---
242+
Delete a postgres database with present connections, might be useful when pgbouncer is used
243243

244244
```yaml
245245
kinda.rocks/postgres-force-delete-db: "true"
246246
```
247+
248+
## Reconciliation logic
249+
250+
By default db-operator checks if a database needs to be reconcilied.
251+
252+
First, use can force a full reconciliation by setting a following annotation:
253+
254+
```yaml
255+
kinda.rocks/db-force-full-reconcile: "true"
256+
```
257+
258+
If it's set, operator will remove it and run the full reconciliation.
259+
260+
Then it checks if it's running in a mode, where it should not check changes and each resource should be fully reconcilied on each loop. Actually, by default it doesn't check and always reconciles databases, but to enable this mode, you need to run the operator with the `--check-for-changes` argument. It might be useful when you have a lot of databases, and updating each one of them might take a very long time.
261+
262+
If you do check for changes, the operator will first check the status of a database and a secret that is used for creating a user. If the status is `false`, or the secret was changed, it will also trigger reconciliation.

docs/dbinstance.md

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,138 @@
11
# DbInstance
22

3-
WIP
3+
Currently, DbInstances are more or less a meta resource that connects the operator to a database server.
4+
5+
> There are actually two types of databases: generic and gsql, and the gsql one is supposed to bootstrap an sql instance in GCP, but they are going to be deprecated soon, and hence I don't feel like writing docs for them. The only important thing about them is that you **shouldn't use them**
6+
7+
Here we only talk about the generic instances
8+
9+
## How to configure a DbInstance
10+
11+
You need to have a **PostgreSQL** or a **MySQL** server running, and it has to be accessible by the operator. You also need a user with sufficient permissions, if it's fine in your environment, I would suggest to use an admin user.
12+
13+
Now let's get started:
14+
```yaml
15+
apiVersion: kinda.rocks/v1beta1
16+
kind: DbInstance
17+
metadata:
18+
name: cloudnative-pg
19+
spec:
20+
adminSecretRef:
21+
Name: cnpg17-admin-creds
22+
Namespace: databases
23+
# -- Legacy settings, please set it like this
24+
# -- it's going to be removed in the next api version
25+
backup:
26+
bucket: ""
27+
engine: postgres
28+
generic:
29+
hostFrom:
30+
key: host
31+
kind: ConfigMap
32+
name: cloudnative-pg-config
33+
namespace: databases
34+
portFrom:
35+
key: port
36+
kind: ConfigMap
37+
name: cloudnative-pg-config
38+
namespace: databases
39+
monitoring:
40+
enabled: false
41+
```
42+
43+
Let's quickly go through the yaml
44+
45+
With `.adminSecretRef` you are pointing the operator to a secret, where the admin credentials are stored.
46+
They must be stored in a following format
47+
48+
```yaml
49+
kind: Secret
50+
data:
51+
# -- user might be omitted, then the following values will be used
52+
# -- for PostgreSQL - postgres
53+
# -- for MySQL - root
54+
user: < base64 encoded admin username >
55+
password: < base64 encoded admin password >
56+
```
57+
58+
With `.engine` you let the operator know, if it should treat a server as a PostgreSQL or a MySQL one. Possible values are `postgres` and `mysql`
59+
60+
Then you need to configure a URL and a port that the operator should try to connect to, there are two options to do that, you can set them directly in the manifest:
61+
62+
```yaml
63+
spec:
64+
generic:
65+
host: ${HOST}
66+
port: ${PORT}
67+
```
68+
69+
Or you can read them from a ConfigMap or a Secret:
70+
71+
```yaml
72+
spec:
73+
generic
74+
hostFrom:
75+
key: host
76+
kind: ConfigMap
77+
name: cloudnative-pg-config
78+
namespace: databases
79+
portFrom:
80+
key: port
81+
kind: ConfigMap
82+
name: cloudnative-pg-config
83+
namespace: databases
84+
```
85+
86+
## Additional configurations
87+
88+
### Extra Grants
89+
90+
To use the `.extraGrants` feature of `Databases`, you need to enabled it on the instance level. To do so, set the `.spec.allowExtraGrants` to `true`
91+
92+
### Allowed Privileges
93+
94+
To use the `.extraPrivileges` feature of `DbUsers`, you also need to enabled the privileges on the instance level. Extra privileges is a list of roles that can be granteed to `DbUsers`. For example:
95+
96+
```yaml
97+
spec:
98+
generic:
99+
allowedPriveleges:
100+
- readOnlyAdmin
101+
- rds-iam
102+
```
103+
104+
Then you will be able to assigned these roles to DbUsers. The roles are not managed by the operator, they must be already on a server when a user is created.
105+
106+
### Instance Vars
107+
108+
It may happen that you need to share the same variable in the Database/DbUser [templates](templates.md). Let's say you have a **RW** and **RO** urls, and your application need two env variables to connect: one - for actibely writing, and another - only for reading.
109+
110+
The **RW** URL will be available anyway, but how to set a **RO** one.
111+
112+
Without the instance vars you could just create a template with a hardcoded string in it:
113+
114+
```yaml
115+
templates:
116+
- name: PG_READONLYHOST
117+
secret: false
118+
template: "my-read-only-postgres-url.test"
119+
```
120+
121+
Or you can use the instance variables.
122+
123+
```yaml
124+
kind: DbInstance
125+
spec:
126+
instanceVars:
127+
PG_READONLYHOST: my-read-only-postgres-url.test
128+
```
129+
130+
And then later use it in a template like that:
131+
```yaml
132+
templates:
133+
- name: PG_READONLYHOST
134+
secret: false
135+
template: '{{ .instanceVar "PG_READONLYHOST" }}'
136+
```
137+
138+
If a value of the variable is changed on the instance, it will be also syned for each Database and User.

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,7 @@ DB: $DATABASE_NAME
157157
PASSWORD: $PASSWORD
158158
USER: $USER
159159
```
160+
161+
### How to rotate passwords?
162+
163+
To rotate a db password with a help of DB Operator, it's enough to remove/update the secret that is used by a database.

mkdocs.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ theme:
44
favicon: assets/logo.png
55
name: material
66
language: en
7-
features:
8-
- navigation.tabs
97

108
palette:
119

0 commit comments

Comments
 (0)