Skip to content

Commit 1f39763

Browse files
committed
err fixed in postgres rotateauth
Signed-off-by: Bonusree <[email protected]>
1 parent 4fe8a5f commit 1f39763

File tree

2 files changed

+71
-48
lines changed

2 files changed

+71
-48
lines changed

docs/guides/pgbouncer/initialization/gitsync.md

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Initialize PgBouncer From Git Repository
33
menu:
44
docs_{{ .version }}:
5-
identifier: guides-mysql-gitsync
5+
identifier: guides-PgBouncer -gitsync
66
name: Git Repository
77
parent: pb-initialization-pgbouncer
88
weight: 20
@@ -15,67 +15,89 @@ section_menu_id: guides
1515
# Initialization PgBouncer from a Git Repository
1616
This guide demonstrates how to use KubeDB to initialize a PgBouncer database with initialization scripts (.sql, .sh, .js and/or .sql.gz) stored in a public or private Git repository.
1717
To fetch the repository contents, KubeDB uses a sidecar container called [git-sync](https://github.com/kubernetes/git-sync).
18-
In this example, we will initialize PgBouncer using a `.sql` script from the GitHub repository [kubedb/mysql-init-scripts](https://github.com/kubedb/mysql-init-scripts).
18+
In this example, we will initialize PgBouncer using a `.sql` script from the GitHub repository [kubedb/PgBouncer -init-scripts](https://github.com/kubedb/PgBouncer -init-scripts).
1919

2020
## Before You Begin
2121

2222
- At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/).
2323

24-
- Now, install KubeDB operator in your cluster by following the steps [here](/docs/setup/README.md).
24+
- Install `KubeDB` Provisioner and Ops-manager operator in your cluster following the steps [here](/docs/setup/README.md).
25+
26+
- You should be familiar with the following `KubeDB` concepts:
27+
- [PgBouncer](/docs/guides/pgbouncer/concepts/pgbouncer.md)
28+
- [PgBouncerOpsRequest](/docs/guides/pgbouncer/concepts/opsrequest.md)
29+
- [Updating Overview](/docs/guides/pgbouncer/update-version/overview.md)
2530

2631
To keep everything isolated, we are going to use a separate namespace called `demo` throughout this tutorial.
32+
2733
```bash
2834
$ kubectl create ns demo
2935
namespace/demo created
3036
```
3137

38+
> **Note:** YAML files used in this tutorial are stored in [docs/examples/pgbouncer](/docs/examples/pgbouncer) directory of [kubedb/docs](https://github.com/kubedb/docs) repository.
39+
40+
### Prepare Postgres
41+
Prepare a KubeDB Postgres cluster using this [tutorial](/docs/guides/postgres/clustering/streaming_replication.md), or you can use any externally managed postgres but in that case you need to create an [appbinding](/docs/guides/pgbouncer/concepts/appbinding.md) yourself. In this tutorial we will use 3 node Postgres cluster named `ha-postgres`.
42+
43+
### Prepare PgBouncer
44+
45+
Now, we are going to deploy a `PgBouncer` with version `1.24.0`.
46+
3247
## From Public Git Repository
3348

34-
KubeDB implements a `MySQL` Custom Resource Definition (CRD) to define the specification of a PgBouncer database.
49+
KubeDB implements a `PgBouncer ` Custom Resource Definition (CRD) to define the specification of a PgBouncer database.
3550
To initialize the database from a public Git repository, you need to specify the required arguments for the `git-sync` sidecar container within the PgBouncer resource specification.
36-
The following YAML manifest shows an example `MySQL` object configured with `git-sync`:
51+
The following YAML manifest shows an example `PgBouncer ` object configured with `git-sync`:
3752

3853
```yaml
3954
apiVersion: kubedb.com/v1
40-
kind: MySQL
55+
kind: PgBouncer
4156
metadata:
42-
name: sample-mysql
57+
name: pb-demo
4358
namespace: demo
4459
spec:
60+
version: "1.24.0"
61+
replicas: 1
62+
database:
63+
syncUsers: true
64+
databaseName: "postgres"
65+
databaseRef:
66+
name: "postgres-demo"
67+
namespace: demo
68+
connectionPool:
69+
maxClientConnections: 20
70+
reservePoolSize: 5
4571
init:
4672
script:
47-
scriptPath: "current"
73+
scriptPath: "sync-test"
4874
git:
4975
args:
50-
- --repo=https://github.com/kubedb/mysql-init-scripts
51-
- --link=current
52-
- --root=/git
53-
# terminate after one successful sync
76+
- --repo=<desired repo>
77+
- --depth=1
78+
- --add-user=true
79+
- --period=60s
5480
- --one-time
55-
version: "9.1.0"
56-
storage:
57-
accessModes:
58-
- ReadWriteOnce
59-
resources:
60-
requests:
61-
storage: 1Gi
62-
deletionPolicy: WipeOut
81+
securityContext:
82+
runAsUser: 999
6383
```
6484
```bash
65-
kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/initialization/yamls/git-sync-public.yaml
66-
MySQL.kubedb.com/sample-PgBouncer created
85+
kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/PgBouncer /initialization/yamls/git-sync-public.yaml
86+
PgBouncer .kubedb.com/sample-PgBouncer created
6787
```
88+
Here,
6889

69-
The `git-sync` container has two required flags:
90+
-`.spec.init.git.securityContext.runAsUser` the init container git_sync runs with user 999.
91+
- `.spec.init.script.git.args` specifies the arguments for the `git-sync` container.
92+
The `git-sync` container has one required flags:
7093
- `--repo` – specifies the remote Git repository to sync.
71-
- `--root` – specifies the working directory where the repository will be cloned.Here name `/git`is fixed
7294

7395
Here, the value of the `--link` argument must match the value of `spec.init.script.scriptPath`.
7496
The `--link` argument creates a symlink that always points to the latest synced data.
7597

7698
> To know more about `git-sync` configuration visit this [link](https://github.com/kubernetes/git-sync).
7799
78-
Now, wait until `sample-mysql` has status `Ready`. i.e,
100+
Now, wait until `sample-PgBouncer ` has status `Ready`. i.e,
79101

80102
```bash
81103
$ kubectl get PgBouncer -n demo
@@ -86,14 +108,14 @@ sample-PgBouncer 9.1.0 Ready 42m
86108
Next, we will connect to the PgBouncer database and verify the data inserted from the `*.sql` script stored in the Git repository.
87109

88110
```bash
89-
$ kubectl get secrets -n demo sample-mysql-auth -o jsonpath='{.data.\username}' | base64 -d
111+
$ kubectl get secrets -n demo sample-PgBouncer -auth -o jsonpath='{.data.\username}' | base64 -d
90112
root⏎
91-
$ kubectl get secrets -n demo sample-mysql-auth -o jsonpath='{.data.\password}' | base64 -d
113+
$ kubectl get secrets -n demo sample-PgBouncer -auth -o jsonpath='{.data.\password}' | base64 -d
92114
lYeFGCL~mklFUN1b⏎
93-
$ kubectl exec -it -n demo sample-mysql-0 -- bash
94-
Defaulted container "mysql" out of: mysql, mysql-init (init), git-sync (init)
115+
$ kubectl exec -it -n demo sample-PgBouncer -0 -- bash
116+
Defaulted container "PgBouncer " out of: PgBouncer , PgBouncer -init (init), git-sync (init)
95117
bash-5.1$ PgBouncer -uroot -p"lYeFGCL~mklFUN1b"
96-
mysql: [Warning] Using a password on the command line interface can be insecure.
118+
PgBouncer : [Warning] Using a password on the command line interface can be insecure.
97119
Welcome to the PgBouncer monitor. Commands end with ; or \g.
98120
Your PgBouncer connection id is 156
99121
Server version: 9.1.0 PgBouncer Community Server - GPL
@@ -106,7 +128,7 @@ owners.
106128

107129
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
108130

109-
mysql> show databases;
131+
PgBouncer > show databases;
110132
+--------------------+
111133
| Database |
112134
+--------------------+
@@ -118,13 +140,13 @@ mysql> show databases;
118140
+--------------------+
119141
5 rows in set (0.02 sec)
120142

121-
mysql> use mysql;
143+
PgBouncer > use PgBouncer ;
122144
Reading table information for completion of table and column names
123145
You can turn off this feature to get a quicker startup with -A
124146

125147
Database changed
126148

127-
mysql> select * from kubedb_table;
149+
PgBouncer > select * from kubedb_table;
128150
+----+-------+
129151
| id | name |
130152
+----+-------+
@@ -133,7 +155,7 @@ mysql> select * from kubedb_table;
133155
| 3 | name3 |
134156
+----+-------+
135157
3 rows in set (0.00 sec)
136-
mysql> select * from kubedb_table;
158+
PgBouncer > select * from kubedb_table;
137159
+----+-------+
138160
| id | name |
139161
+----+-------+
@@ -172,13 +194,13 @@ $ kubectl create secret generic -n demo git-creds \
172194
--from-file=known_hosts=/tmp/known_hosts
173195
```
174196
175-
The following YAML manifest provides an example of a `MySQL` resource configured to use `git-sync` with a private Git repository:
197+
The following YAML manifest provides an example of a `PgBouncer ` resource configured to use `git-sync` with a private Git repository:
176198
177199
```yaml
178200
apiVersion: kubedb.com/v1
179-
kind: MySQL
201+
kind: PgBouncer
180202
metadata:
181-
name: sample-mysql
203+
name: sample-PgBouncer
182204
namespace: demo
183205
spec:
184206
init:
@@ -209,8 +231,8 @@ spec:
209231
```
210232
211233
```bash
212-
kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/initialization/yamls/git-sync-ssh.yaml
213-
MySQL.kubedb.com/sample-PgBouncer created
234+
kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/PgBouncer /initialization/yamls/git-sync-ssh.yaml
235+
PgBouncer .kubedb.com/sample-PgBouncer created
214236
```
215237
216238
Here,
@@ -229,14 +251,14 @@ $ kubectl create secret generic -n demo git-pat \
229251
--from-literal=github-pat=<ghp_yourpersonalaccesstoken>
230252
```
231253
232-
Now, create a `MySQL` resource that references the secret created above.
254+
Now, create a `PgBouncer ` resource that references the secret created above.
233255
The following YAML manifest shows an example:
234256
235257
```yaml
236258
apiVersion: kubedb.com/v1
237-
kind: MySQL
259+
kind: PgBouncer
238260
metadata:
239-
name: sample-mysql
261+
name: sample-PgBouncer
240262
namespace: demo
241263
spec:
242264
init:
@@ -268,8 +290,8 @@ spec:
268290
```
269291
270292
```bash
271-
kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/initialization/yamls/git-sync-pat.yaml
272-
MySQL.kubedb.com/sample-PgBouncer created
293+
kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/PgBouncer /initialization/yamls/git-sync-pat.yaml
294+
PgBouncer .kubedb.com/sample-PgBouncer created
273295
```
274296
275297
Once the database reaches the `Ready` state, you can verify the data using the method described above.
@@ -280,6 +302,6 @@ Once the database reaches the `Ready` state, you can verify the data using the m
280302
To clean up the Kubernetes resources created by this tutorial, run:
281303
282304
```bash
283-
$ kubectl delete PgBouncer -n demo sample-mysql
305+
$ kubectl delete PgBouncer -n demo sample-PgBouncer
284306
$ kubectl delete ns demo
285307
```

docs/guides/postgres/rotate-authentication/rotateauth.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ section_menu_id: guides
1414
**Rotate Authentication** is a feature of the KubeDB Ops-Manager that allows you to rotate a `Postgres` user's authentication credentials using a `PostgresOpsRequest`. There are two ways to perform this rotation.
1515

1616
1. **Operator Generated:** The KubeDB operator automatically generates a random credential, updates the existing secret with the new credential The KubeDB operator automatically generates a random credential and updates the existing secret with the new credential..
17-
2. **User Defined:** The user can create their own credentials by defining a secret of type `kubernetes.io/basic-auth` containing the desired `username` and `password` and then reference this secret in the `PostgresOpsRequest`.
17+
2. **User Defined:** The user can create their own credentials by defining a secret of type `kubernetes.io/basic-auth` containing the desired `password` and then reference this secret in the `PostgresOpsRequest`.
1818

1919
## Before You Begin
2020

@@ -245,11 +245,12 @@ The above output shows that the password has been changed successfully. The prev
245245
#### 2. Using user created credentials
246246

247247
At first, we need to create a secret with kubernetes.io/basic-auth type using custom username and password. Below is the command to create a secret with kubernetes.io/basic-auth type,
248+
> **Note:** Can not change the username while rotating authentication. The username must be same as 'postgres' which is the current username of the database.
248249

249250
```shell
250251
$ kubectl create secret generic quick-postgres-user-auth -n demo \
251252
--type=kubernetes.io/basic-auth \
252-
--from-literal=username=admin \
253+
--from-literal=username=postgres \
253254
--from-literal=password=postgres-secret
254255
secret/quick-postgres-user-auth created
255256
```
@@ -386,7 +387,7 @@ Events:
386387
$ kubectl get pg -n demo quick-postgres -ojson | jq .spec.authSecret.name
387388
"quick-postgres-user-auth"
388389
$ kubectl get secret -n demo quick-postgres-user-auth-new -o=jsonpath='{.data.username}' | base64 -d
389-
admin
390+
postgres
390391
$ kubectl get secret -n demo quick-postgres-user-auth-new -o=jsonpath='{.data.password}' | base64 -d
391392
postgres-secret
392393
```

0 commit comments

Comments
 (0)