Skip to content

Commit b177ef4

Browse files
authored
chore(postgresql-cluster): adaptation drycc (#19)
1 parent c98da89 commit b177ef4

28 files changed

Lines changed: 320 additions & 264 deletions

File tree

addons/index.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
apiVersion: v1
22
entries:
3+
cloudbeaver:
4+
- version: 23
5+
description: "Cloud Database Manager."
36
mysql-cluster:
47
- version: 8.0
58
description: "The world's most popular open source database cluster."
Lines changed: 128 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,154 @@
1-
# ⚠️ Repo Archive Notice
21

3-
As of Nov 13, 2020, charts in this repo will no longer be updated.
4-
For more information, see the Helm Charts [Deprecation and Archive Notice](https://github.com/helm/charts#%EF%B8%8F-deprecation-and-archive-notice), and [Update](https://helm.sh/blog/charts-repo-deprecation/).
5-
6-
# Patroni Helm Chart
7-
8-
This directory contains a Kubernetes chart to deploy a five node [Patroni](https://github.com/zalando/patroni/) cluster using a [Spilo](https://github.com/zalando/spilo) and a StatefulSet.
2+
# Postgresql cluster addons
3+
## Plans
94

5+
View and choose the service resource specifications you need.
6+
```
7+
# drycc resources:plans postgresql-cluster
8+
```
9+
### Resource specification list
10+
| Resource Specification | Cores | MEMORY | Storage SIZE |
11+
| :---: | :---: | :---: | :---: |
12+
| standard-10 | 1C | 2G | 10G |
13+
| standard-20 | 2C | 4G | 20G |
14+
| standard-50 | 2C | 8G | 50G |
15+
| standard-100 | 4C | 16G | 100G |
16+
| standard-200 | 8C | 32G | 200G |
17+
| standard-400 | 16C | 64G | 400G |
18+
| standard-800 | 32C | 128G | 800G |
19+
20+
In order to obtain a better experience, it is recommended not to exceed 80% usage of resource utilization for a long period of time. If there is a need for larger resource scale, please apply for private customization.
21+
22+
## Create Postgresql Cluster Service instance
23+
24+
- Create Postgresql service
25+
```
26+
# drycc resources:create postgresql-cluster:standard-10 `my_pg_001`
27+
```
28+
- View service status
29+
```
30+
# drycc resources:describe `my_pg_001`
31+
```
32+
- Bind service
33+
```
34+
# drycc resources:bind `my_pg_001`
35+
```
36+
- View resource status
37+
```
38+
# drycc resources:describe `my_pg_001`
39+
```
1040

11-
## Prerequisites Details
12-
* Kubernetes 1.9+
13-
* PV support on the underlying infrastructure
41+
## Create Service with values file
1442

15-
## StatefulSet Details
16-
* https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
43+
`vim values.yaml`
44+
```
45+
# create or update pg instance template yaml
46+
networkPolicy.allowNamespaces:
47+
- mx-test1
48+
service.type: ClusterIP
49+
metrics.enabled: true
50+
backup:
51+
# whether BackUP should be enabled
52+
enabled: true
53+
# Cron schedule for doing base backups
54+
scheduleCronJob: "20 0 * * 0"
55+
Amount of base backups to retain
56+
retainBackups: 2
57+
s3:
58+
awsAccessKeyID: ""
59+
awsSecretAccessKey: ""
60+
walGS3Prefix: "s3://xx"
61+
awsEndpoint: "http://xxxx:9000"
62+
awsS3ForcePathStyle: "true"
63+
awsRegion: dx-1
64+
```
65+
```
66+
drycc resources:create postgresql-cluster:standard-10 `my_pg_001` -f ./values.yaml
67+
```
1768

18-
## StatefulSet Caveats
19-
* https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations
69+
## Update Service
70+
### Create app user and database
2071

72+
- Login database web with admin user & password
2173

22-
## Chart Details
23-
This chart will do the following:
74+
- CREATE APP USER
75+
```
76+
CREATE USER `my_user` WITH CONNECTION LIMIT `conn_limit` LOGIN ENCRYPTED PASSWORD 'password';
77+
```
78+
- CREATE APP DATABASE
79+
```
80+
CREATE DATABASE `my_db` OWNER `my_user`;
81+
```
82+
- CREATE EXTENSIONS
83+
```
84+
CREATE EXTENSION pg_buffercache;
85+
```
2486

25-
* Implement a HA scalable PostgreSQL 10 cluster using a Kubernetes StatefulSet.
87+
### Network Access
2688

27-
## Installing the Chart
89+
Default access allow policy: only namespace scope.
2890

29-
To install the chart with the release name `my-release`:
91+
- allow `mx-test1` namespace access
3092

31-
```console
32-
$ helm repo add
33-
$ helm dependency update
34-
$ helm install --name my-release postgresql-cluster
93+
`vim values.yaml `
3594
```
36-
37-
To install the chart with randomly generated passwords:
38-
39-
```console
40-
$ helm install --name my-release postgresql-cluster \
41-
--set credentials.superuser="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32)",credentials.admin="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32)",credentials.standby="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32)"
95+
networkPolicy.allowNamespaces:
96+
- mx-test1
4297
```
43-
44-
## Connecting to PostgreSQL
45-
46-
Your access point is a cluster IP. In order to access it spin up another pod:
47-
48-
```console
49-
$ kubectl run -i --tty --rm psql --image=postgres --restart=Never -- bash -il
5098
```
51-
52-
Then, from inside the pod, connect to PostgreSQL:
53-
54-
```console
55-
$ psql -U admin -h my-release-patroni.default.svc.cluster.local postgres
56-
<admin password from values.yaml>
57-
postgres=>
99+
drycc resources:update postgresql-cluster:standard-10 `my_pg_001` -f ./values.yaml
58100
```
59101

60-
## Configuration
61-
62-
The following table lists the configurable parameters of the patroni chart and their default values.
102+
- Assign external network IP address
63103

64-
| Parameter | Description | Default |
65-
|-----------------------------------|---------------------------------------------|-----------------------------------------------------|
66-
| `nameOverride` | Override the name of the chart | `nil` |
67-
| `fullnameOverride` | Override the fullname of the chart | `nil` |
68-
| `replicaCount` | Amount of pods to spawn | `5` |
69-
| `image.repository` | The image to pull | `registry.opensource.zalan.do/acid/spilo-10` |
70-
| `image.tag` | The version of the image to pull | `1.5-p5` |
71-
| `image.pullPolicy` | The pull policy | `IfNotPresent` |
72-
| `credentials.superuser` | Password of the superuser | `tea` |
73-
| `credentials.admin` | Password of the admin | `cola` |
74-
| `credentials.standby` | Password of the replication user | `pinacolada` |
75-
| `kubernetes.dcs.enable` | Using Kubernetes as DCS | `true` |
76-
| `kubernetes.configmaps.enable` | Using Kubernetes configmaps instead of endpoints | `false` |
77-
| `etcd.enable` | Using etcd as DCS | `false` |
78-
| `etcd.deployChart` | Deploy etcd chart | `false` |
79-
| `etcd.host` | Host name of etcd cluster | `nil` |
80-
| `etcd.discovery` | Domain name of etcd cluster | `nil` |
81-
| `zookeeper.enable` | Using ZooKeeper as DCS | `false` |
82-
| `zookeeper.deployChart` | Deploy ZooKeeper chart | `false` |
83-
| `zookeeper.hosts` | List of ZooKeeper cluster members | `host1:port1,host2:port,etc...` |
84-
| `consul.enable` | Using Consul as DCS | `false` |
85-
| `consul.deployChart` | Deploy Consul chart | `false` |
86-
| `consul.host` | Host name of consul cluster | `nil` |
87-
| `env` | Extra custom environment variables | `{}` |
88-
| `walE.enable` | Use of Wal-E tool for base backup/restore | `false` |
89-
| `walE.scheduleCronJob` | Schedule of Wal-E backups | `00 01 * * *` |
90-
| `walE.retainBackups` | Number of base backups to retain | `2` |
91-
| `walE.s3Bucket:` | Amazon S3 bucket used for wal-e backups | `nil` |
92-
| `walE.gcsBucket` | GCS storage used for Wal-E backups | `nil` |
93-
| `walE.kubernetesSecret` | K8s secret name for provider bucket | `nil` |
94-
| `walE.backupThresholdMegabytes` | Maximum size of the WAL segments accumulated after the base backup to consider WAL-E restore instead of pg_basebackup | `1024` |
95-
| `walE.backupThresholdPercentage` | Maximum ratio (in percents) of the accumulated WAL files to the base backup to consider WAL-E restore instead of pg_basebackup | `30` |
96-
| `resources` | Any resources you wish to assign to the pod | `{}` |
97-
| `nodeSelector` | Node label to use for scheduling | `{}` |
98-
| `tolerations` | List of node taints to tolerate | `[]` |
99-
| `affinityTemplate` | A template string to use to generate the affinity settings | Anti-affinity preferred on hostname |
100-
| `affinity` | Affinity settings. Overrides `affinityTemplate` if set. | `{}` |
101-
| `schedulerName` | Alternate scheduler name | `nil` |
102-
| `persistentVolume.accessModes` | Persistent Volume access modes | `[ReadWriteOnce]` |
103-
| `persistentVolume.annotations` | Annotations for Persistent Volume Claim` | `{}` |
104-
| `persistentVolume.mountPath` | Persistent Volume mount root path | `/home/postgres/pgdata` |
105-
| `persistentVolume.size` | Persistent Volume size | `2Gi` |
106-
| `persistentVolume.storageClass` | Persistent Volume Storage Class | `volume.alpha.kubernetes.io/storage-class: default` |
107-
| `persistentVolume.subPath` | Subdirectory of Persistent Volume to mount | `""` |
108-
| `rbac.create` | Create required role and rolebindings | `true` |
109-
| `serviceAccount.create` | If true, create a new service account | `true` |
110-
| `serviceAccount.name` | Service account to be used. If not set and `serviceAccount.create` is `true`, a name is generated using the fullname template | `nil` |
104+
`vim values.yaml`
105+
```
106+
service.type: LoadBlancer
107+
```
108+
```
109+
drycc resources:update postgresql-cluster:standard-10 `my_pg_001` -f ./values.yaml
110+
```
111+
- View resource status
112+
```
113+
# drycc resources:describe `my_pg_001`
114+
```
111115

112-
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
116+
### Manger backup your data `Very important`
117+
118+
`Strongly recommend enabling this feature.`
119+
`Strongly recommend enabling this feature.`
120+
`Strongly recommend enabling this feature.`
113121

114-
Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,
122+
PG data backup use S3 as backenp store. Choose an independent storage space `outside of the current environment` as your backup space.
115123

116-
```console
117-
$ helm install --name my-release -f values.yaml incubator/patroni
124+
`vim values.yaml`
125+
```
126+
backup:
127+
# whether BackUP should be enabled
128+
enabled: true
129+
# Cron schedule for doing base backups
130+
scheduleCronJob: "20 0 * * 0"
131+
Amount of base backups to retain
132+
retainBackups: 2
133+
s3:
134+
awsAccessKeyID: DO9l771LqiwZkhhz
135+
awsSecretAccessKey: R3Dv0NEmJBo8JFdn1q8jz49ArWwpDjFn
136+
walGS3Prefix: mx-test
137+
```
138+
```
139+
drycc resources:update postgresql-cluster:standard-10 `my_pg_001` -f ./values.yaml
118140
```
119141

120-
> **Tip**: You can use the default [values.yaml](values.yaml)
142+
You can modify multiple content at once, there is no need to modify part of it each time.
121143

122-
## Cleanup
123144

124-
To remove the spawned pods you can run a simple `helm delete <release-name>`.
145+
## Destroy Service
125146

126-
Helm will however preserve created persistent volume claims,
127-
to also remove them execute the commands below.
128-
129-
```console
130-
$ release=<release-name>
131-
$ helm delete $release
132-
$ kubectl delete pvc -l release=$release
133-
```
134-
135-
## Internals
136-
137-
Patroni is responsible for electing a PostgreSQL master pod by leveraging the
138-
DCS of your choice. After election it adds a `spilo-role=master` label to the
139-
elected master and set the label to `spilo-role=replica` for all replicas.
140-
Simultaneously it will update the `<release-name>-patroni` endpoint to let the
141-
service route traffic to the elected master.
142-
143-
```console
144-
$ kubectl get pods -l spilo-role -L spilo-role
145-
NAME READY STATUS RESTARTS AGE SPILO-ROLE
146-
my-release-patroni-0 1/1 Running 0 9m replica
147-
my-release-patroni-1 1/1 Running 0 9m master
148-
my-release-patroni-2 1/1 Running 0 8m replica
149-
my-release-patroni-3 1/1 Running 0 8m replica
150-
my-release-patroni-4 1/1 Running 0 8m replica
147+
- Unbind service first
148+
```
149+
# drycc resources:unbind `my_pg_001`
150+
```
151+
- Destroy service
151152
```
153+
# drycc resources:destroy `my_pg_001`
154+
```

0 commit comments

Comments
 (0)