Skip to content

Commit e7773e3

Browse files
fix(helm): Medcat trainer helm chart run as single pod (#40)
* fix(helm): Fix medcat-trainer log buffer. Fix load examples * fix(helm): Medcat trainer deployment should run as one pod with both nginx and the api * fix(helm): Trainer service selectorlabels fix * feat(helm): Medcat-trainer helm to restart pod when configmap changes
1 parent 98ff6ac commit e7773e3

11 files changed

Lines changed: 79 additions & 149 deletions

deployment/kubernetes/charts/medcat-trainer-helm/templates/NOTES.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "medcat-trainer-helm.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
1616
echo http://$SERVICE_IP:{{ .Values.service.port }}
1717
{{- else if contains "ClusterIP" .Values.service.type }}
18-
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "medcat-trainer-helm.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=nginx" -o jsonpath="{.items[0].metadata.name}")
19-
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "medcat-trainer-helm.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=medcat-trainer" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[?(@.name==\"nginx\")].ports[0].containerPort}")
2020
echo "Visit http://127.0.0.1:8080 to use your application"
2121
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
2222
{{- end }}

deployment/kubernetes/charts/medcat-trainer-helm/templates/ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ spec:
3535
{{- end }}
3636
backend:
3737
service:
38-
name: {{ include "medcat-trainer-helm.fullname" $ }}-nginx
38+
name: {{ include "medcat-trainer-helm.fullname" $ }}-medcat-trainer
3939
port:
4040
number: {{ $.Values.service.port }}
4141
{{- end }}

deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-configmap.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ data:
1717
pidfile=/var/run/supervisord.pid
1818
1919
[program:medcattrainer]
20-
command=sh -c "exec /home/scripts/run.sh 2>&1 | sed 's/^/[medcattrainer] /'"
20+
command=sh -c "exec /home/scripts/run.sh 2>&1 | sed -u 's/^/[medcattrainer] /'"
2121
stdout_logfile=/dev/stdout
2222
stdout_logfile_maxbytes=0
2323
stderr_logfile=/dev/stderr
2424
stderr_logfile_maxbytes=0
2525
autorestart=true
2626
2727
[program:bg-process]
28-
command=sh -c "exec /home/scripts/run-bg-process.sh 2>&1 | sed 's/^/[bg-process] /'"
28+
command=sh -c "exec /home/scripts/run-bg-process.sh 2>&1 | sed -u 's/^/[bg-process] /'"
2929
stdout_logfile=/dev/stdout
3030
stdout_logfile_maxbytes=0
3131
stderr_logfile=/dev/stderr
3232
stderr_logfile_maxbytes=0
3333
autorestart=true
3434
3535
[program:db-backup]
36-
command=sh -c "exec cron -f -l 2 2>&1 | sed 's/^/[db-backup] /'"
36+
command=sh -c "exec cron -f -l 2 2>&1 | sed -u 's/^/[db-backup] /'"
3737
stdout_logfile=/dev/stdout
3838
stdout_logfile_maxbytes=0
3939
stderr_logfile=/dev/stderr

deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-deployment.yaml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ metadata:
44
name: {{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer
55
labels:
66
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
7-
app.kubernetes.io/component: medcat-trainer
87
spec:
98
{{- if not .Values.autoscaling.enabled }}
109
replicas: {{ .Values.replicaCount }}
1110
{{- end }}
1211
selector:
1312
matchLabels:
1413
{{- include "medcat-trainer-helm.selectorLabels" . | nindent 6 }}
15-
app.kubernetes.io/component: medcat-trainer
1614
strategy: {{ toYaml .Values.updateStrategy | nindent 4 }}
1715
template:
1816
metadata:
19-
{{- with .Values.podAnnotations }}
2017
annotations:
18+
{{- with .Values.podAnnotations }}
2119
{{- toYaml . | nindent 8 }}
2220
{{- end }}
21+
checksum/medcat-trainer-configmap: {{ include (print $.Template.BasePath "/medcat-trainer-configmap.yaml") . | sha256sum }}
22+
checksum/medcat-trainer-env-configmap: {{ include (print $.Template.BasePath "/medcat-trainer-env-configmap.yaml") . | sha256sum }}
23+
checksum/medcat-trainer-secret: {{ include (print $.Template.BasePath "/medcat-trainer-secret.yaml") . | sha256sum }}
24+
checksum/nginx-configmap: {{ include (print $.Template.BasePath "/nginx-configmap.yaml") . | sha256sum }}
2325
labels:
2426
{{- include "medcat-trainer-helm.labels" . | nindent 8 }}
25-
app.kubernetes.io/component: medcat-trainer
2627
{{- with .Values.podLabels }}
2728
{{- toYaml . | nindent 8 }}
2829
{{- end }}
@@ -45,8 +46,8 @@ spec:
4546
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
4647
imagePullPolicy: {{ .Values.image.pullPolicy }}
4748
ports:
48-
- name: http
49-
containerPort: 8000
49+
- name: api
50+
containerPort: {{ .Values.service.apiPort }}
5051
protocol: TCP
5152
args:
5253
- /usr/bin/supervisord
@@ -93,6 +94,43 @@ spec:
9394
{{- with .Values.volumeMounts }}
9495
{{- toYaml . | nindent 12 }}
9596
{{- end }}
97+
- name: nginx
98+
{{- with .Values.securityContext }}
99+
securityContext:
100+
{{- toYaml . | nindent 12 }}
101+
{{- end }}
102+
image: "{{ .Values.nginxImage.repository }}:{{ .Values.nginxImage.tag }}"
103+
imagePullPolicy: {{ .Values.nginxImage.pullPolicy }}
104+
ports:
105+
- name: http
106+
containerPort: {{ .Values.service.port }}
107+
protocol: TCP
108+
{{- with .Values.nginx.livenessProbe }}
109+
livenessProbe:
110+
{{- toYaml . | nindent 12 }}
111+
{{- end }}
112+
{{- with .Values.nginx.readinessProbe }}
113+
readinessProbe:
114+
{{- toYaml . | nindent 12 }}
115+
{{- end }}
116+
{{- with .Values.resources }}
117+
resources:
118+
{{- toYaml . | nindent 12 }}
119+
{{- end }}
120+
volumeMounts:
121+
- name: nginx-config
122+
mountPath: /etc/nginx/nginx.conf
123+
subPath: nginx.conf
124+
- name: nginx-config
125+
mountPath: /etc/nginx/sites-enabled/medcattrainer
126+
subPath: sitesenabled.medcattrainer
127+
- mountPath: /home/api/media
128+
name: api-media
129+
- mountPath: /home/api/static
130+
name: api-static
131+
{{- with .Values.volumeMounts }}
132+
{{- toYaml . | nindent 12 }}
133+
{{- end }}
96134
volumes:
97135
- name: medcat-trainer-config
98136
configMap:
@@ -111,6 +149,9 @@ spec:
111149
persistentVolumeClaim:
112150
claimName: {{ include "medcat-trainer-helm.fullname" . }}-api-db-backup
113151
{{- end }}
152+
- name: nginx-config
153+
configMap:
154+
name: {{ include "medcat-trainer-helm.fullname" . }}-nginx-config
114155
{{- with .Values.volumes }}
115156
{{- toYaml . | nindent 8 }}
116157
{{- end }}

deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-env-configmap.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ data:
1212
DB_BACKUP_DIR: "/home/api/db-backup"
1313
DB_DIR: "/home/api/db"
1414
DB_PATH: "/home/api/db/db.sqlite3"
15+
MCT_VERSION: {{ .Values.image.tag | default .Chart.AppVersion }}
16+
API_URL: http://localhost:{{ .Values.service.apiPort }}/api/
1517
{{- range $key, $value := .Values.env }}
1618
{{ $key }}: {{ $value | quote }}
1719
{{- end }}

deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-secret.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: {{ include "medcat-trainer-helm.fullname" . }}-secret
55
labels:
66
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
7+
app.kubernetes.io/component: medcat-trainer
78
stringData:
89
DB_NAME: {{ .Values.postgresql.auth.database }}
910
DB_USER: "{{ .Values.postgresql.auth.username }}"

deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ data:
165165
}
166166
167167
location / {
168-
proxy_pass http://{{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer:8000;
168+
proxy_pass http://localhost:8000;
169169
proxy_set_header Host $host;
170170
proxy_set_header X-Real-IP $remote_addr;
171171
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-deployment.yaml

Lines changed: 0 additions & 102 deletions
This file was deleted.

deployment/kubernetes/charts/medcat-trainer-helm/templates/service.yaml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@ metadata:
44
name: {{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer
55
labels:
66
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
7-
app.kubernetes.io/component: medcat-trainer
8-
spec:
9-
type: ClusterIP
10-
ports:
11-
- port: 8000
12-
targetPort: http
13-
protocol: TCP
14-
name: http
15-
selector:
16-
{{- include "medcat-trainer-helm.selectorLabels" . | nindent 4 }}
17-
app.kubernetes.io/component: medcat-trainer
18-
---
19-
apiVersion: v1
20-
kind: Service
21-
metadata:
22-
name: {{ include "medcat-trainer-helm.fullname" . }}-nginx
23-
labels:
24-
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
25-
app.kubernetes.io/component: nginx
267
spec:
278
type: {{ .Values.service.type }}
289
ports:
@@ -33,7 +14,10 @@ spec:
3314
targetPort: http
3415
protocol: TCP
3516
name: http
17+
- port: {{ .Values.service.apiPort }}
18+
targetPort: api
19+
protocol: TCP
20+
name: api
3621
selector:
3722
{{- include "medcat-trainer-helm.selectorLabels" . | nindent 4 }}
38-
app.kubernetes.io/component: nginx
3923
---

deployment/kubernetes/charts/medcat-trainer-helm/values.yaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ replicaCount: 1
99
image:
1010
repository: cogstacksystems/medcat-trainer
1111
# This sets the pull policy for images.
12-
pullPolicy: IfNotPresent
12+
pullPolicy: Always
1313
# Overrides the image tag whose default is the chart appVersion.
1414
tag: "latest"
1515
nginxImage:
@@ -33,6 +33,7 @@ env:
3333
OPENBLAS_NUM_THREADS: "1"
3434
RESUBMIT_ALL_ON_STARTUP: "0"
3535
UNIQUE_DOC_NAMES_IN_DATASETS: "True"
36+
VITE_USE_OIDC: "0"
3637

3738
# TODO: Support custom DB overrides#
3839
# DB_ENGINE: "sqlite3"
@@ -162,8 +163,10 @@ service:
162163
# This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
163164
type: ClusterIP
164165
# This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports
165-
port: 8000
166-
166+
port: 8001
167+
apiPort: 8000 # Note medcat-trainer API is currently hardcoded on 8000 in the run.sh script
168+
# nodePort: 30001
169+
167170
# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/
168171
ingress:
169172
enabled: false
@@ -188,27 +191,28 @@ resources: {}
188191
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
189192
# limits:
190193
# cpu: 3 # Recommended to leave unset. If desired to set note service performance has been found to improve up to around 3 CPU.
191-
# memory: 2Gi
194+
# memory: 4Gi
192195
# requests:
193-
# cpu: 1
194-
# memory: 1Gi
196+
# cpu: 2 # For reference loading the examples on startup measured to use 2CPU and 2Gi memory
197+
# memory: 2Gi
195198

196199
# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
197200
livenessProbe:
198201
httpGet:
199-
path: /api/health/live/
200-
port: http
202+
path: /api/health/live/?format=json
203+
port: api
204+
failureThreshold: 30
201205
readinessProbe:
202206
httpGet:
203-
path: /api/health/ready/
204-
port: http
207+
path: /api/health/ready/?format=json
208+
port: api
205209
startupProbe:
206210
httpGet:
207-
path: /api/health/startup/
208-
port: http
211+
path: /api/health/startup/?format=json
212+
port: api
209213
failureThreshold: 30
210214
periodSeconds: 10
211-
initialDelaySeconds: 5
215+
initialDelaySeconds: 15
212216

213217
nginx:
214218
livenessProbe:

0 commit comments

Comments
 (0)