Skip to content

Commit 7dab4d7

Browse files
committed
SYS-665 add postgres instance to nexus helm chart
1 parent 896b62e commit 7dab4d7

11 files changed

Lines changed: 232 additions & 5 deletions

File tree

ansible/roles/kubernetes/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757

5858
- name: Set up control plane
5959
include_tasks: cplane.yml
60-
when: k8s.cplane | length > 0
60+
when: k8s.cplane
6161

6262
- name: Join cluster
6363
include_tasks: join.yml
64-
when: k8s.cplane | length == 0
64+
when: not k8s.cplane
6565

6666
- name: Add RequiresMountsFor to kubelet.service
6767
copy:

k8s/helm/nexus/Chart.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ home: https://github.com/instantlinux/docker-tools
55
sources:
66
- https://github.com/instantlinux/docker-tools
77
type: application
8-
version: 0.1.11
9-
# TODO: see vendor instructions for 3.71+ database migration
10-
appVersion: "3.70.3"
8+
version: 0.1.12
9+
appVersion: "3.87.1"
1110
dependencies:
1211
- name: chartlib
1312
version: 0.1.8
1413
repository: https://instantlinux.github.io/docker-tools
14+
- name: postgres
15+
version: 0.1.0
16+
repository: file://subcharts/postgres
17+
condition: postgres.enabled
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
.git
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v2
2+
name: postgres
3+
description: PostgreSQL database
4+
home: https://github.com/instantlinux/docker-tools
5+
sources:
6+
- https://github.com/instantlinux/docker-tools
7+
- https://hub.docker.com/_/postgres
8+
type: application
9+
version: 0.1.0
10+
# specify version tag from hub.docker.com in top-level values.yaml
11+
appVersion: "0.0.1"
12+
dependencies:
13+
- name: chartlib
14+
version: 0.1.8
15+
repository: https://instantlinux.github.io/docker-tools
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{- if hasKey .Values "service" }}
2+
{{- if or .Values.service.enabled (not (hasKey .Values.service "enabled")) }}
3+
1. Get the application URL by running these commands:
4+
{{- if hasKey .Values "ingress" }}
5+
{{- if .Values.ingress.enabled }}
6+
{{- range $host := .Values.ingress.hosts }}
7+
{{- range .paths }}
8+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
9+
{{- end }}
10+
{{- end }}
11+
{{- else if contains "NodePort" .Values.service.type }}
12+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "local.fullname" . }})
13+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
14+
echo http://$NODE_IP:$NODE_PORT
15+
{{- else if contains "LoadBalancer" .Values.service.type }}
16+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
17+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "local.fullname" . }}'
18+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "local.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
19+
echo http://$SERVICE_IP:{{ .Values.service.port }}
20+
{{- else if contains "ClusterIP" .Values.service.type }}
21+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "local.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
22+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
23+
echo "Visit http://127.0.0.1:8080 to use your application"
24+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
25+
{{- end }}
26+
{{- end }}
27+
{{- end }}
28+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- include "chartlib.configmap" . }}
2+
---
3+
{{- include "chartlib.deployment" . }}
4+
---
5+
{{- include "chartlib.hpa" . }}
6+
---
7+
{{- include "chartlib.ingress" . }}
8+
---
9+
{{- include "chartlib.ingresstotp" . }}
10+
---
11+
{{- include "chartlib.service" . }}
12+
---
13+
{{- include "chartlib.serviceaccount" . }}
14+
---
15+
{{- include "chartlib.statefulset" . }}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{{- $fullName := include "local.fullname" . -}}
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
name: {{ include "local.fullname" . }}
6+
labels:
7+
{{- include "local.labels" . | nindent 4 }}
8+
spec:
9+
schedule: "{{ .Values.backup.schedule }}"
10+
timeZone: {{ .Values.backup.timeZone }}
11+
jobTemplate:
12+
spec:
13+
template:
14+
spec:
15+
containers:
16+
- name: {{ $fullName }}-backup
17+
image: alpine/psql:{{ (split "-" .Values.image.tag)._0 }}
18+
env:
19+
- name: PGPASSFILE
20+
value: /.pgpass
21+
command:
22+
- /bin/sh
23+
- -c
24+
- "pg_dump
25+
-U synapse
26+
-h {{ $fullName }}
27+
-p 5432
28+
-d homeserver | gzip > /mnt/postgres/homeserver-$(date '+%Y-%m-%d-%H-%M').sql.gz 2>> /mnt/postgres/backup_error.log"
29+
resources:
30+
requests:
31+
cpu: 500m
32+
memory: 256Mi
33+
volumeMounts:
34+
- name: backup
35+
mountPath: /mnt
36+
- name: pgpass-secret
37+
mountPath: /.pgpass
38+
subPath: .pgpass
39+
volumes:
40+
- name: backup
41+
hostPath: { path: /var/lib/docker/k8s-volumes/backup }
42+
- name: pgpass-secret
43+
secret:
44+
secretName: synapse
45+
defaultMode: 0600
46+
restartPolicy: Never
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if hasKey .Values "service" }}
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: "{{ include "local.fullname" . }}-test-connection"
6+
labels:
7+
{{- include "local.labels" . | nindent 4 }}
8+
annotations:
9+
"helm.sh/hook": test
10+
spec:
11+
containers:
12+
- name: wget
13+
image: busybox
14+
command: ['wget']
15+
args: ['{{ include "local.fullname" . }}:{{ .Values.service.port }}']
16+
restartPolicy: Never
17+
{{- end }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Default values for postgres
2+
backup:
3+
# Min Hour Day Month Weekday
4+
timeZone: America/Los_Angeles
5+
schedule: "0 5 * * *"
6+
7+
statefulset:
8+
containerPorts: [ containerPort: 5432 ]
9+
# environment variables defined in parent
10+
env:
11+
postgres_user: user
12+
postgres_db: appdb
13+
xenv:
14+
- name: POSTGRES_PASSWORD
15+
valueFrom:
16+
secretKeyRef:
17+
key: database_password
18+
name: postgres
19+
replicas: 1
20+
resources:
21+
limits:
22+
memory: 2048Mi
23+
requests:
24+
cpu: 300m
25+
memory: 256Mi
26+
volumeMounts:
27+
- mountPath: /var/lib/postgresql/data
28+
name: pgdata
29+
volumeClaimTemplates:
30+
- metadata:
31+
name: pgdata
32+
spec:
33+
accessModes: [ ReadWriteOnce ]
34+
resources:
35+
requests:
36+
storage: 8Gi
37+
38+
image:
39+
repository: postgres
40+
pullPolicy: IfNotPresent
41+
# tag: default
42+
43+
nameOverride: ""
44+
fullnameOverride: ""
45+
46+
serviceAccount:
47+
enabled: false
48+
service:
49+
clusterIP: None
50+
ports: [ port: 5432 ]
51+
type: ClusterIP
52+
autoscaling:
53+
enabled: false

k8s/helm/nexus/templates/app.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{- include "chartlib.configmap" . }}
2+
---
13
{{- include "chartlib.deployment" . }}
24
---
35
{{- include "chartlib.hpa" . }}

0 commit comments

Comments
 (0)