Skip to content

Commit fd9daff

Browse files
committed
feat: fix postgres persistence
BREAKING CHANGE: create db password secret; move values in frond- and backend; use ImplementationSpecific ingress path on backend
1 parent 29ddc35 commit fd9daff

File tree

9 files changed

+98
-376
lines changed

9 files changed

+98
-376
lines changed

README.md

+15-23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ It's recommended to use a dedicated PostgreSQL instance for production usage.
1717
1. install and run minikube or other local K8s services https://kubernetes.io/docs/tasks/tools/
1818
2. use scripts in installation below
1919

20+
### Minikube
21+
22+
```bash
23+
$ minikube addons enable ingress
24+
$ minikube tunnel
25+
```
26+
2027
## Installation
2128

2229
### Recommendations
@@ -31,31 +38,17 @@ It's recommended to use a dedicated PostgreSQL instance for production usage.
3138
CoreDNS.
3239
* For production usage, may use an own postgres instance. (Recommended, use
3340
the [Cloud Native PG Operator](https://cloudnative-pg.io) in Kubernetes)
41+
*
3442

35-
### Installation steps
43+
### Installation & upgrade steps
3644

3745
1. Prepare the value files.
3846
2. Install the helm charts with `helm install ...` CLI Command:
3947

4048
```bash
41-
# Create a namespace (or use default), where to work in:
42-
$ kubectl create namespace terminfinder-demo
43-
44-
# First installing the helm chart, to the name
45-
$ helm install terminfinder-demo terminfinder-chart -n terminfinder-demo
46-
47-
# Verify installation of helm charts:
48-
$ helm list -n terminfinder-demo
49-
$ kubectl get deploy -n terminfinder-demo
50-
```
51-
52-
### Upgrade release
53-
54-
To upgrade the helm chart, use the `helm upgrade ...` command:
55-
56-
```bash
57-
# Upgrade HelmChart
58-
$ helm upgrade terminfinder-demo terminfinder-chart -n terminfinder-demo
49+
$ helm upgrade --install -n tf --create-namespace tf1 terminfinder-chart
50+
$ helm list -n tf
51+
$ kubectl get pod,deploy,pvc,svc,ing,ep -n tf
5952
```
6053

6154
### Debug Container
@@ -71,10 +64,9 @@ To delete the helm chart (release), use the `helm uninstall...` command.
7164
Note that the persistent volume may be available even if the helm release is uninstalled.
7265

7366
```bash
74-
# Delete namespace
75-
$ helm uninstall terminfinder-demo -n terminfinder-demo
76-
$ kubectl delete pvc --all -n terminfinder-demo
77-
$ kubectl delete namespace terminfinder-demo
67+
$ helm uninstall tf1 -n tf
68+
$ kubectl delete pvc --all -n tf
69+
$ kubectl delete namespace tf
7870
```
7971

8072
## Using an own PostgreSQL DB instance

terminfinder-chart/charts/terminfinder-backend/templates/NOTES.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
{{- else if contains "ClusterIP" .Values.service.type }}
1818
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "terminfinder-backend.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
1919
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20-
echo "Visit http://127.0.0.1:8080 to use your application"
21-
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22-
{{- end }}
20+
echo "Visit http://127.0.0.1:{{ .Values.application.port}} to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME {{ .Values.application.port }}:$CONTAINER_PORT
22+
{{- end }}

terminfinder-chart/charts/terminfinder-backend/templates/deployment.yaml

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- $svc := .Values.global.postgresql.service.name | default (printf "%s-postgresql" .Release.Name) }}
1+
{{- $svc := printf "%s-postgresql" .Release.Name }}
22
apiVersion: apps/v1
33
kind: Deployment
44
metadata:
@@ -45,26 +45,30 @@ spec:
4545
- name: DB_USERNAME
4646
value: {{ .Values.global.postgresql.auth.username }}
4747
- name: ASPNETCORE_URLS
48-
value: http://+:8080
49-
# Secrets:
48+
value: {{printf "http://+:%d" (int .Values.application.port) }}
5049
- name: DB_PASSWORD
5150
valueFrom:
5251
secretKeyRef:
53-
name: {{ .Values.global.postgresql.auth.existingSecret | default (printf "%s" $svc) }}
54-
key: {{ .Values.global.postgresql.auth.secretKeys.userPasswordKey | default "password" }}
55-
# Patches
52+
name: {{ required "Postgres DB secret name not set" .Values.global.postgresql.auth.existingSecret }}
53+
key: {{ required "Postgres DB password secretkey not set" .Values.global.postgresql.auth.secretKeys.userPasswordKey }}
5654
- name: Terminfinder__UseHttps
5755
value: "false"
5856
- name: Terminfinder__UseCors
59-
value: "false"
57+
value: {{ .Values.application.useCors | quote }}
6058
- name: Terminfinder__Log4NetConfigFilename
6159
value: log4net.Console.debug.config
6260
- name: ConnectionStrings__TerminfinderConnection
6361
value: "Server=$(DB_ADDRESS),$(DB_PORT);Database=$(DB_DATABASE);User ID=$(DB_USERNAME);password=$(DB_PASSWORD);"
6462
ports:
6563
- name: http
66-
containerPort: 8080
64+
containerPort: {{ int .Values.application.port }}
6765
protocol: TCP
66+
command:
67+
- "dotnet"
68+
- "Dataport.Terminfinder.WebAPI.dll"
69+
{{- if .Values.application.migrateDB }}
70+
- "--dbmigrate"
71+
{{- end }}
6872
startupProbe:
6973
failureThreshold: 3
7074
periodSeconds: 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: postgresql-default-auth
5+
type: kubernetes.io/basic-auth
6+
stringData:
7+
password: {{ randAlphaNum 20 | b64enc | quote }}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
# Default values for terminfinder-backend.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
4-
51
global:
62
postgresql:
73
auth:
8-
username: terminfinder
94
database: terminfinder
10-
existingSecret: "" # if not set, default: "{{ Release.Name }}-postgres"
5+
username: terminfinder
6+
existingSecret: postgresql-default-auth
117
secretKeys:
12-
userPasswordKey: "" # if not set, default: "password"
8+
userPasswordKey: password
139
service:
14-
name: "" # if not set, default: "{{ Release.Name }}-postgres"
1510
ports:
16-
postgresql: 5432 # Default port
11+
postgresql: 5432
1712

1813
replicaCount: 1
1914

@@ -22,17 +17,20 @@ image:
2217
pullPolicy: IfNotPresent
2318
tag: "0.1.0"
2419

20+
application:
21+
port: 8080
22+
useCors: true
23+
migrateDB: true
24+
2525
imagePullSecrets: [ ]
26+
2627
nameOverride: ""
28+
2729
fullnameOverride: ""
2830

2931
serviceAccount:
30-
# Specifies whether a service account should be created
3132
create: true
32-
# Annotations to add to the service account
3333
annotations: { }
34-
# The name of the service account to use.
35-
# If not set and create is true, a name is generated using the fullname template
3634
name: ""
3735

3836
podAnnotations: { }
@@ -51,31 +49,24 @@ securityContext:
5149

5250
service:
5351
type: ClusterIP
54-
port: 80
52+
port: 8080
5553

5654
ingress:
57-
enabled: false
55+
enabled: true
5856
className: "nginx"
5957
annotations:
60-
{ }
61-
# kubernetes.io/ingress.class: nginx
62-
# nginx.ingress.kubernetes.io/rewrite-target: /
63-
# nginx.ingress.kubernetes.io/ssl-redirect: "true"
64-
# cert-manager.io/cluster-issuer: letsencrypt-production
58+
nginx.ingress.kubernetes.io/use-regex: "true"
59+
nginx.ingress.kubernetes.io/rewrite-target: /$2
60+
nginx.ingress.kubernetes.io/enable-cors: "true"
6561
hosts:
66-
- host: terminfinder.opencode.de
62+
- host: localhost
63+
port: 80
6764
paths:
68-
- path: /api
69-
pathType: Prefix
65+
- path: /api(/|$)(.*)
66+
pathType: ImplementationSpecific
7067
tls: [ ]
71-
# - secretName: cert-terminfinder.opencode.de
72-
# hosts:
73-
# - terminfinder.de
7468

7569
resources:
76-
# We recommend to not use limits, since workload spikes can hinder the application or cause crashes
77-
# due to OOM errors. Read more about it here:
78-
# https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-resource-requests-and-limits?hl=en
7970
limits:
8071
cpu: 500m
8172
memory: 256Mi
@@ -99,27 +90,28 @@ affinity: { }
9990
postgresql:
10091
enabled: true
10192

102-
serviceAccount:
103-
create: true
93+
auth:
94+
enablePostgresUser: false
10495

105-
## Set permissions for the data volume
106-
## Only needed when volume has not correct permissions
107-
volumePermissions:
108-
enabled: true
96+
primary:
97+
persistence:
98+
enabled: true
10999

110-
image:
111-
registry: docker.io # Notice, may this is not allowed
112-
repository: bitnami/bitnami-shell
113-
# tag: 11-debian-11-r77
114-
# pullPolicy: Always
115-
# pullSecrets: []
100+
resources:
101+
requests:
102+
memory: 256Mi
103+
cpu: 250m
104+
limits:
105+
memory: 256Mi
106+
cpu: 250m
116107

117108
initdb:
118-
# Enabling the UUID-OSSP
119109
scripts:
120110
99-enable-uuid.sql: |
121111
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
122112
ALTER EXTENSION "uuid-ossp" SET SCHEMA public;
123113
124-
# More variables / parameters can be found here:
125-
# https://github.com/bitnami/charts/tree/main/bitnami/postgresql#parameters
114+
readReplicas:
115+
replicaCount: 0
116+
persistence:
117+
enabled: false

terminfinder-chart/charts/terminfinder-frontend/templates/NOTES.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{- else if contains "ClusterIP" .Values.service.type }}
1818
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "terminfinder-frontend.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
1919
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20-
echo "Visit http://127.0.0.1:8080 to use your application"
21-
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
20+
echo "Visit http://127.0.0.1:80 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 80:$CONTAINER_PORT
2222
{{- end }}
2323
2. Don't forget to deploy the Backend!

terminfinder-chart/charts/terminfinder-frontend/templates/deployment.yaml

+10-8
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ spec:
3535
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3636
imagePullPolicy: {{ .Values.image.pullPolicy }}
3737
env:
38-
- name: ADDRESSING
39-
value: {{ .Values.customerConfig.ADDRESSING }}
40-
- name: LOCALE
41-
value: {{ .Values.customerConfig.LOCALE }}
38+
- name: CUSTOMER_ID
39+
value: {{ required "no customerId set" .Values.application.customerId }}
40+
- name: API_URL
41+
value: {{ .Values.application.apiUrl }}
4242
- name: TITLE
43-
value: {{ .Values.customerConfig.TITLE }}
43+
value: {{ .Values.application.title }}
44+
- name: LOCALE
45+
value: {{ required "no locale set" .Values.application.locale }}
46+
- name: ADDRESSING
47+
value: {{ required "no addressing set" .Values.application.addressing }}
4448
- name: EMAIL
45-
value: {{ .Values.customerConfig.EMAIL }}
46-
- name: API_URL
47-
value: {{ .Values.app.backend_url }}
49+
value: {{ required "no email set" .Values.application.email }}
4850
ports:
4951
- name: http
5052
containerPort: 8080

terminfinder-chart/charts/terminfinder-frontend/values.yaml

+13-36
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
# Default values for terminfinder-frontend.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
1+
application:
2+
customerId: "80248A42-8FE2-4D4A-89DA-02E683511F76"
3+
apiUrl: ""
4+
title: ""
5+
locale: "de-DE"
6+
addressing: "du"
7+
email: "demo@demo.demo"
48

5-
customerConfig:
6-
ADDRESSING: "du" # supported: du, sie
7-
LOCALE: "de-DE" # supported: DE-de, EN-en
8-
TITLE: "Terminfinder Demo"
9-
EMAIL: ""
10-
11-
app:
12-
backend_url: https://terminfinder.opencode.de/api # Public URL to Backend
13-
14-
replicaCount: 1 # Not HA for now!
9+
replicaCount: 1
1510

1611
image:
1712
repository: registry.opencode.de/dataport/terminfinder/terminfinder-frontend
@@ -23,12 +18,8 @@ nameOverride: ""
2318
fullnameOverride: ""
2419

2520
serviceAccount:
26-
# Specifies whether a service account should be created
27-
create: true
28-
# Annotations to add to the service account
21+
create: false
2922
annotations: { }
30-
# The name of the service account to use.
31-
# If not set and create is true, a name is generated using the fullname template
3223
name: ""
3324

3425
podAnnotations: { }
@@ -41,39 +32,26 @@ podSecurityContext:
4132

4233
securityContext:
4334
capabilities:
44-
# add:
45-
# - NET_BIND_SERVICE
4635
drop:
4736
- ALL
4837
readOnlyRootFilesystem: false
49-
# runAsUser: 1000
5038

5139
service:
5240
type: ClusterIP
53-
port: 80
41+
port: 8080
5442

5543
ingress:
56-
enabled: false
44+
enabled: true
5745
className: "nginx"
58-
annotations:
59-
{ }
60-
# kubernetes.io/ingress.class: nginx
61-
# nginx.ingress.kubernetes.io/ssl-redirect: "true"
62-
# cert-manager.io/cluster-issuer: letsencrypt-production
6346
hosts:
64-
- host: terminfinder.opencode.de
47+
- host: localhost
48+
port: 80
6549
paths:
6650
- path: /
6751
pathType: Prefix
6852
tls: [ ]
69-
# - secretName: cert-terminfinder.opencode.de
70-
# hosts:
71-
# - terminfinder.de
7253

7354
resources:
74-
# We recommend to not use limits, since workload spikes can hinder the application or cause crashes
75-
# due to OOM errors. Read more about it here:
76-
# https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-resource-requests-and-limits?hl=en
7755
limits:
7856
cpu: 500m
7957
memory: 256Mi
@@ -86,7 +64,6 @@ autoscaling:
8664
minReplicas: 1
8765
maxReplicas: 20
8866
targetCPUUtilizationPercentage: 80
89-
# targetMemoryUtilizationPercentage: 80
9067

9168
nodeSelector: { }
9269

0 commit comments

Comments
 (0)