Skip to content

Commit 3a28182

Browse files
committed
feat(drycc-addons): add postgresql-cluster
1 parent bde3a37 commit 3a28182

16 files changed

Lines changed: 872 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
annotations:
2+
category: Database
3+
apiVersion: v2
4+
appVersion: "15"
5+
dependencies:
6+
- name: common
7+
repository: oci://registry.drycc.cc/charts
8+
version: ~1.1.1
9+
description: PostgreSQL (Postgres) is an open source object-relational database known for reliability and data integrity. ACID-compliant, it supports foreign keys, joins, views, triggers and stored procedures.
10+
engine: gotpl
11+
home: https://github.com/bitnami/charts/tree/master/bitnami/postgresql
12+
icon: https://bitnami.com/assets/stacks/postgresql/img/postgresql-stack-220x234.png
13+
keywords:
14+
- postgresql
15+
- postgres
16+
- database
17+
- sql
18+
- replication
19+
- cluster
20+
maintainers:
21+
- email: zhang.eamon@hotmail.com
22+
name: zhangeamon
23+
name: postgresql
24+
sources:
25+
- https://github.com/drycc-addons/
26+
- https://www.postgresql.org/
27+
version: 15.4.1
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# ⚠️ Repo Archive Notice
2+
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.
9+
10+
11+
## Prerequisites Details
12+
* Kubernetes 1.9+
13+
* PV support on the underlying infrastructure
14+
15+
## StatefulSet Details
16+
* https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
17+
18+
## StatefulSet Caveats
19+
* https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations
20+
21+
22+
## Chart Details
23+
This chart will do the following:
24+
25+
* Implement a HA scalable PostgreSQL 10 cluster using a Kubernetes StatefulSet.
26+
27+
## Installing the Chart
28+
29+
To install the chart with the release name `my-release`:
30+
31+
```console
32+
$ helm repo add
33+
$ helm dependency update
34+
$ helm install --name my-release postgresql-cluster
35+
```
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)"
42+
```
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
50+
```
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=>
58+
```
59+
60+
## Configuration
61+
62+
The following table lists the configurable parameters of the patroni chart and their default values.
63+
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` |
111+
112+
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
113+
114+
Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,
115+
116+
```console
117+
$ helm install --name my-release -f values.yaml incubator/patroni
118+
```
119+
120+
> **Tip**: You can use the default [values.yaml](values.yaml)
121+
122+
## Cleanup
123+
124+
To remove the spawned pods you can run a simple `helm delete <release-name>`.
125+
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
151+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Patroni can be accessed via port 5432 on the following DNS name from within your cluster:
2+
{{ template "patroni.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
3+
4+
To get your password for superuser run:
5+
6+
# superuser password
7+
PGPASSWORD_SUPERUSER=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "patroni.fullname" . }} -o jsonpath="{.data.password-superuser}" | base64 --decode)
8+
9+
# admin password
10+
PGPASSWORD_ADMIN=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "patroni.fullname" . }} -o jsonpath="{.data.password-admin}" | base64 --decode)
11+
12+
To connect to your database:
13+
14+
1. Run a postgres pod and connect using the psql cli:
15+
# login as superuser
16+
kubectl run -i --tty --rm psql --image=postgres \
17+
--env "PGPASSWORD=$PGPASSWORD_SUPERUSER" \
18+
--command -- psql -U postgres \
19+
-h {{ template "patroni.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local postgres
20+
21+
# login as admin
22+
kubectl run -i -tty --rm psql --image=postgres \
23+
--env "PGPASSWORD=$PGPASSWORD_ADMIN" \
24+
--command -- psql -U admin \
25+
-h {{ template "patroni.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local postgres
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "patroni.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "patroni.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "patroni.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
33+
34+
{{/*
35+
Create the name of the service account to use.
36+
*/}}
37+
{{- define "patroni.serviceAccountName" -}}
38+
{{- if .Values.serviceAccount.create -}}
39+
{{ default (include "patroni.fullname" .) .Values.serviceAccount.name }}
40+
{{- else -}}
41+
{{ default "default" .Values.serviceAccount.name }}
42+
{{- end -}}
43+
{{- end -}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Endpoints
3+
metadata:
4+
name: {{ template "patroni.fullname" . }}
5+
namespace: {{ include "common.names.namespace" . | quote }}
6+
labels:
7+
app: {{ template "patroni.fullname" . }}
8+
chart: {{ template "patroni.chart" . }}
9+
release: {{ .Release.Name }}
10+
heritage: {{ .Release.Service }}
11+
cluster-name: {{ template "patroni.fullname" . }}
12+
subsets: []
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{- /*
2+
Copyright VMware, Inc.
3+
SPDX-License-Identifier: APACHE-2.0
4+
*/}}
5+
6+
{{- if .Values.networkPolicy.enabled }}
7+
kind: NetworkPolicy
8+
apiVersion: {{ template "common.capabilities.networkPolicy.apiVersion" . }}
9+
metadata:
10+
name: {{ template "common.names.fullname" . }}
11+
namespace: {{ include "common.names.namespace" . | quote }}
12+
labels: {{- include "common.labels.standard" . | nindent 4 }}
13+
{{- if .Values.commonLabels }}
14+
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
15+
{{- end }}
16+
{{- if .Values.commonAnnotations }}
17+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
18+
{{- end }}
19+
spec:
20+
podSelector:
21+
matchLabels:
22+
{{- include "common.labels.matchLabels" . | nindent 6 }}
23+
ingress:
24+
# Allow inbound connections
25+
- ports:
26+
- port: 5432
27+
{{- if and .Values.metrics.enabled }}
28+
- port: {{ .Values.metrics.service.port }}
29+
{{ end }}
30+
{{- if or .Values.networkPolicy.allowCurrentNamespace .Values.networkPolicy.allowNamespaces }}
31+
from:
32+
{{- if .Values.networkPolicy.allowCurrentNamespace }}
33+
- namespaceSelector:
34+
matchLabels:
35+
kubernetes.io/metadata.name: {{ .Release.Namespace }}
36+
{{- end }}
37+
{{- range $namespace := .Values.networkPolicy.allowNamespaces }}
38+
{{- if $namespace }}
39+
- namespaceSelector:
40+
matchLabels:
41+
kubernetes.io/metadata.name: {{ $namespace }}
42+
{{- end }}
43+
{{- end }}
44+
{{- end }}
45+
{{- end }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{- if .Values.rbac.create }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: {{ template "patroni.fullname" . }}
6+
namespace: {{ include "common.names.namespace" . | quote }}
7+
labels:
8+
app: {{ template "patroni.fullname" . }}
9+
chart: {{ template "patroni.chart" . }}
10+
release: {{ .Release.Name }}
11+
heritage: {{ .Release.Service }}
12+
rules:
13+
- apiGroups: [""]
14+
resources: ["configmaps"]
15+
verbs:
16+
- create
17+
- get
18+
- list
19+
- patch
20+
- update
21+
- watch
22+
# delete is required only for 'patronictl remove'
23+
- delete
24+
- apiGroups: [""]
25+
resources: ["services"]
26+
verbs:
27+
- create
28+
- apiGroups: [""]
29+
resources: ["endpoints"]
30+
verbs:
31+
- create
32+
- get
33+
- patch
34+
- update
35+
# the following three privileges are necessary only when using endpoints
36+
- list
37+
- watch
38+
# delete is required only for for 'patronictl remove'
39+
- delete
40+
- deletecollection
41+
- apiGroups: [""]
42+
resources: ["pods"]
43+
verbs:
44+
- get
45+
- list
46+
- patch
47+
- update
48+
- watch
49+
{{- end }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.rbac.create }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: {{ template "patroni.fullname" . }}
6+
namespace: {{ include "common.names.namespace" . | quote }}
7+
labels:
8+
app: {{ template "patroni.fullname" . }}
9+
chart: {{ template "patroni.chart" . }}
10+
release: {{ .Release.Name }}
11+
heritage: {{ .Release.Service }}
12+
subjects:
13+
- kind: ServiceAccount
14+
name: {{ template "patroni.serviceAccountName" . }}
15+
roleRef:
16+
apiGroup: rbac.authorization.k8s.io
17+
kind: Role
18+
name: {{ template "patroni.fullname" . }}
19+
{{- end }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: {{ template "patroni.fullname" . }}
5+
namespace: {{ include "common.names.namespace" . | quote }}
6+
labels:
7+
app: {{ template "patroni.fullname" . }}
8+
chart: {{ template "patroni.chart" . }}
9+
release: {{ .Release.Name }}
10+
heritage: {{ .Release.Service }}
11+
cluster-name: {{ template "patroni.fullname" . }}
12+
type: Opaque
13+
data:
14+
password-superuser: {{ .Values.credentials.superuser | b64enc }}
15+
password-admin: {{ .Values.credentials.admin | b64enc }}
16+
password-replication: {{ .Values.credentials.standby | b64enc }}

0 commit comments

Comments
 (0)