Skip to content

Commit 681656c

Browse files
authored
Merge pull request zalando#312 from zalando-incubator/feature/doc-clone
Add an example of clone feature
2 parents 59795d4 + 2a05179 commit 681656c

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

docs/user.md

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ spec:
3434
## Create a new Spilo cluster
3535
3636
```bash
37-
$ kubectl create -f manifests/minimal-postgres-manifest.yaml
37+
$ kubectl create -f manifests/minimal-postgres-manifest.yaml
3838
```
3939

4040
## Watch pods being created
4141

4242
```bash
43-
$ kubectl get pods -w --show-labels
43+
$ kubectl get pods -w --show-labels
4444
```
4545

4646
## Connect to PostgreSQL
4747

4848
We can use the generated secret of the `postgres` robot user to connect to our `acid-minimal-cluster` master running in Minikube:
4949

5050
```bash
51-
$ export PGHOST=db_host
52-
$ export PGPORT=db_port
53-
$ export PGPASSWORD=$(kubectl get secret postgres.acid-minimal-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
54-
$ psql -U postgres
51+
$ export PGHOST=db_host
52+
$ export PGPORT=db_port
53+
$ export PGPASSWORD=$(kubectl get secret postgres.acid-minimal-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
54+
$ psql -U postgres
5555
```
5656

5757
# Defining database roles in the operator
@@ -162,14 +162,14 @@ definitions will be ignored with a prior warning.
162162
See [infrastructure roles secret](https://github.com/zalando-incubator/postgres-operator/blob/master/manifests/infrastructure-roles.yaml)
163163
and [infrastructure roles configmap](https://github.com/zalando-incubator/postgres-operator/blob/master/manifests/infrastructure-roles-configmap.yaml) for the examples.
164164

165-
#### Use taints and tolerations for dedicated PostgreSQL nodes
165+
## Use taints and tolerations for dedicated PostgreSQL nodes
166166

167167
To ensure Postgres pods are running on nodes without any other application
168168
pods, you can use
169169
[taints and tolerations](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/)
170170
and configure the required toleration in the manifest.
171171

172-
```
172+
```yaml
173173
apiVersion: "acid.zalan.do/v1"
174174
kind: postgresql
175175
metadata:
@@ -181,3 +181,64 @@ spec:
181181
operator: Exists
182182
effect: NoSchedule
183183
```
184+
185+
## How to clone an existing PostgreSQL cluster
186+
187+
You can spin up a new cluster as a clone of the existing one, using a clone
188+
section in the spec. There are two options here:
189+
190+
* Clone directly from a source cluster using `pg_basebackup`
191+
192+
* Clone from an S3 bucket
193+
194+
### Clone directly
195+
196+
```yaml
197+
apiVersion: "acid.zalan.do/v1"
198+
kind: postgresql
199+
200+
metadata:
201+
name: acid-test-cluster
202+
spec:
203+
clone:
204+
cluster: "acid-batman"
205+
```
206+
207+
Here `cluster` is a name of a source cluster that is going to be cloned. The
208+
cluster to clone is assumed to be running and the clone procedure invokes
209+
`pg_basebackup` from it. The operator will connect to the service by name (if
210+
the cluster is called test, then the connection string will look like host=test
211+
port=5432), which means that you can clone only from clusters running in the
212+
default namespace.
213+
214+
### Clone from S3
215+
216+
```yaml
217+
apiVersion: "acid.zalan.do/v1"
218+
kind: postgresql
219+
220+
metadata:
221+
name: acid-test-cluster
222+
spec:
223+
clone:
224+
uid: "efd12e58-5786-11e8-b5a7-06148230260c"
225+
cluster: "acid-batman"
226+
timestamp: "2017-12-19T12:40:33+01:00"
227+
```
228+
229+
Here `cluster` is a name of a source cluster that is going to be cloned. A new
230+
cluster will be cloned from S3, using the latest backup before the
231+
`timestamp`. In this case, `uid` field is also mandatory - operator will use it
232+
to find a correct key inside an S3 bucket. You can find this field from
233+
metadata of a source cluster:
234+
235+
```yaml
236+
apiVersion: acid.zalan.do/v1
237+
kind: postgresql
238+
metadata:
239+
name: acid-test-cluster
240+
uid: efd12e58-5786-11e8-b5a7-06148230260c
241+
```
242+
243+
Note that timezone required for `timestamp` (offset relative to UTC, see RFC
244+
3339 section 5.6)

manifests/complete-postgres-manifest.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ spec:
4848
# with a non-empty timestamp, clone from an S3 bucket using the latest backup before the timestamp
4949
# with an empty/absent timestamp, clone from an existing alive cluster using pg_basebackup
5050
# clone:
51+
# uid: "efd12e58-5786-11e8-b5a7-06148230260c"
5152
# cluster: "acid-batman"
5253
# timestamp: "2017-12-19T12:40:33+01:00" # timezone required (offset relative to UTC, see RFC 3339 section 5.6)
5354
maintenanceWindows:

0 commit comments

Comments
 (0)