Skip to content

Commit

Permalink
ISSUE-163=helm (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
paunin authored Jun 5, 2018
1 parent 8e1f822 commit 92a7913
Show file tree
Hide file tree
Showing 20 changed files with 533 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

PostgreSQL cluster with **High Availability** and **Self Healing** features for any cloud and docker environment (Amazon, Google Cloud, Kubernetes, Docker Compose, Docker Swarm, Apache Mesos)

<img align="right" width="400" src="https://github.com/paunin/PostDock/blob/master/artwork/logo.png?raw=true">
![Formula](./artwork/formula2.png)

[![Build Status](https://travis-ci.org/paunin/PostDock.svg?branch=master)](https://travis-ci.org/paunin/PostDock)

- [Info](#info)
* [Features](#features)
Expand Down Expand Up @@ -30,8 +32,6 @@ PostgreSQL cluster with **High Availability** and **Self Healing** features for

-------

[![Build Status](https://travis-ci.org/paunin/PostDock.svg?branch=master)](https://travis-ci.org/paunin/PostDock)

## Info
### Features
* High Availability
Expand Down Expand Up @@ -95,6 +95,10 @@ Please check comments for each `ENV` variable in [./docker-compose/latest.yml](.

## Start cluster in Kubernetes

### Using Helm (recomended for production)
You can install PostDock with [Helm](https://helm.sh/) package manager check the [README.md of the package](./k8s/helm/PostDock/README.md) for more information

### Simple (NOT recomended for production)
To make it easier repository contains services' objects under `k8s` dir. Setup `PostgreSQL` cluster following the steps in [the example](./k8s/README.md). It also has information how to check cluster state

## Configuring the cluster
Expand Down
Binary file added artwork/formula1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artwork/formula2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified artwork/logo.psd
Binary file not shown.
18 changes: 18 additions & 0 deletions k8s/helm/PostDock/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
appVersion: "1.0"
description: Postdock chart for kubernetes
name: PostDock
version: 1.2.0
maintainers:
- name: Dmitry Paunin
email: [email protected]
home: https://github.com/paunin/PostDock
sources:
- https://github.com/paunin/PostDock
icon: https://raw.githubusercontent.com/paunin/PostDock/master/artwork/logo.png
keywords:
- database
- postgres
- postgresql
- postdock
- cluster
4 changes: 4 additions & 0 deletions k8s/helm/PostDock/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
approvers:
- paunin
reviewers:
- paunin
24 changes: 24 additions & 0 deletions k8s/helm/PostDock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# PostDock Helm Chart

Includes Postgres, Pgpool, Barman components
## Install the chart

```console
$ helm install [--name my-release] <path to chart>
```

## Upgrade the chart

```console
$ helm upgrade my-release <path to chart>
```

## Uninstalling the Chart

```console
$ helm delete my-release
```

## Customization

Please see [values.yaml](./values.yaml) file to understand what each of variables means in order to customize it for your needs
13 changes: 13 additions & 0 deletions k8s/helm/PostDock/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
May the force be with you in this release of {{ .Chart.Name }}={{ .Release.Name }}

Your database will be accessible through pgpool k8s service:
* Host - {{ .Values.postDock.name }}-pgpool
* Port - 5432
* User - {{ .Values.postgres.db.user }}
* Database - {{ .Values.postgres.db.name }}

To read:
* Useful commands - https://github.com/paunin/PostDock#useful-commands
* Recovery of cluster from backups - https://github.com/paunin/PostDock/blob/master/doc/RECOVERY.md
* Documentation - https://github.com/paunin/PostDock
* Issues tracker - https://github.com/paunin/PostDock/issues
15 changes: 15 additions & 0 deletions k8s/helm/PostDock/templates/barman/claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ if .Values.barman.backupSchedule }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: barman-data-{{ .Values.postDock.name }}-barman-node-0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.barman.volume.size }}
selector:
matchLabels:
system: {{ .Values.postDock.name }}-barman
{{ end }}
68 changes: 68 additions & 0 deletions k8s/helm/PostDock/templates/barman/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{ if .Values.barman.backupSchedule }}
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: {{ .Values.postDock.name }}-barman-node
labels:
name: barman
system: {{ .Values.postDock.name }}
app: {{ .Values.postDock.name }}
spec:
updateStrategy:
type: RollingUpdate
replicas: 1
serviceName: "{{ .Values.postDock.name }}-barman"
template:
metadata:
labels:
name: database
system: {{ .Values.postDock.name }}
spec:
containers:
- name: barman-node
image: {{ .Values.barman.image }}:{{ .Values.barman.tag }}
{{ if .Values.barman.resources }}
resources:
{{ toYaml .Values.barman.resources | indent 12 }}
{{ end }}
env:
{{ if .Values.barman.env }}
{{ toYaml .Values.barman.env | indent 12 }}
{{ end }}
- name: "BACKUP_SCHEDULE"
value: {{ .Values.barman.backupSchedule | quote }}
- name: "POSTGRES_DB"
valueFrom:
configMapKeyRef:
name: {{ .Values.postDock.name }}-config
key: app.db.database
- name: "POSTGRES_USER"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.user
- name: "POSTGRES_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.password
- name: "REPLICATION_USER"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.cluster.replication.user
- name: "REPLICATION_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.cluster.replication.password
# @todo: should be service which always points to master - https://github.com/paunin/PostDock/issues/137
- name: "REPLICATION_HOST"
value: {{ .Values.postDock.name }}-db-node-0.{{ .Values.postDock.name }}-db
volumeMounts:
- name: barman-data
mountPath: /var/backups
volumeClaimTemplates:
- metadata:
name: barman-data
{{ end }}
17 changes: 17 additions & 0 deletions k8s/helm/PostDock/templates/barman/volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ if .Values.barman.backupSchedule }}
{{ if .Values.barman.volume.definition }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: barman-data-{{ $.Values.postDock.name }}
labels:
system: {{ $.Values.postDock.name }}-barman
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: {{ .Values.barman.volume.size }}
persistentVolumeReclaimPolicy: {{ .Values.barman.volume.recalimPolicy }}
{{ toYaml .Values.barman.volume.definition | indent 2 }}
{{ end }}
{{ end }}
73 changes: 73 additions & 0 deletions k8s/helm/PostDock/templates/pgpool/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Values.postDock.name }}-database-pgpool
labels:
name: database-balancer
node: pgpool
system: {{ .Values.postDock.name }}
app: {{ .Values.postDock.name }}
spec:
replicas: {{ .Values.pgpool.replicas }}
revisionHistoryLimit: 5
template:
metadata:
name: database-pgpool
labels:
name: database-balancer
node: pgpool
system: {{ .Values.postDock.name }}
app: {{ .Values.postDock.name }}
spec:
containers:
- name: database-pgpool
image: {{ .Values.pgpool.image }}:{{ .Values.pgpool.tag }}
livenessProbe:
exec:
command: ['bash', '-c', '/usr/local/bin/pgpool/has_write_node.sh && /usr/local/bin/pgpool/has_enough_backends.sh']
initialDelaySeconds: 600
timeoutSeconds: 10
periodSeconds: 30
successThreshold: 1
failureThreshold: 3
imagePullPolicy: Always
{{ if .Values.pgpool.resources }}
resources:
{{ toYaml .Values.pgpool.resources | indent 10 }}
{{ end }}
ports:
- containerPort: 5432
env:
{{ if .Values.pgpool.env }}
{{ toYaml .Values.pgpool.env | indent 10 }}
{{ end }}
- name: "PCP_USER"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.pool.pcp.user
- name: "PCP_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.pool.pcp.password
- name: "CHECK_USER"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.cluster.replication.user
- name: "CHECK_PASSWORD"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.cluster.replication.password
- name: "DB_USERS"
valueFrom:
secretKeyRef:
name: {{ .Values.postDock.name }}-secret
key: app.db.pool.users
- name: "BACKENDS"
valueFrom:
configMapKeyRef:
name: {{ .Values.postDock.name }}-config
key: app.db.pool.backends
16 changes: 16 additions & 0 deletions k8s/helm/PostDock/templates/pgpool/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.postDock.name }}-pgpool
labels:
name: database-balancer
node: pgpool
system: {{ .Values.postDock.name }}
spec:
ports:
- port: 5432
targetPort: 5432
selector:
name: database-balancer
node: pgpool
system: {{ .Values.postDock.name }}
17 changes: 17 additions & 0 deletions k8s/helm/PostDock/templates/postgres/claims.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ range $i, $e := .Values.postgres.nodes }}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: db-data-{{ $.Values.postDock.name }}-db-node-{{ $i }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $e.volume.size }}
selector:
matchLabels:
system: {{ $.Values.postDock.name }}-db
node: node-{{ $i }}
{{ end }}
11 changes: 11 additions & 0 deletions k8s/helm/PostDock/templates/postgres/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.postDock.name }}-config
labels:
app: {{ .Values.postDock.name }}
data:
app.db.database: "{{ .Values.postgres.db.name }}"
app.db.cluster.name: "{{ .Values.postgres.clusterName }}"
app.db.cluster.replication.db: "{{ .Values.postgres.replicationDb.name }}"
app.db.pool.backends: "{{ range $i, $e := .Values.postgres.nodes }}{{ if $i }},{{ end }}{{ $i }}:{{ $.Values.postDock.name }}-db-node-{{ $i }}.{{ $.Values.postDock.name }}-db::::{{ end }}"
13 changes: 13 additions & 0 deletions k8s/helm/PostDock/templates/postgres/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.postDock.name }}-secret
type: Opaque
data:
app.db.user: {{ .Values.postgres.db.user | b64enc }}
app.db.password: {{ .Values.postgres.db.password | b64enc }}
app.db.cluster.replication.user: {{ .Values.postgres.replicationDb.user | b64enc }}
app.db.cluster.replication.password: {{ .Values.postgres.replicationDb.password | b64enc }}
app.db.pool.users: {{ .Values.pgpool.users | b64enc }}
app.db.pool.pcp.user: {{ .Values.pgpool.pcp.user | b64enc }}
app.db.pool.pcp.password: {{ .Values.pgpool.pcp.password | b64enc }}
16 changes: 16 additions & 0 deletions k8s/helm/PostDock/templates/postgres/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.postDock.name }}-db
labels:
name: database
system: {{ .Values.postDock.name }}
spec:
clusterIP: None
ports:
- port: 5432
targetPort: 5432
selector:
name: database
system: {{ .Values.postDock.name }}

Loading

0 comments on commit 92a7913

Please sign in to comment.