Skip to content

Commit c1bc5d7

Browse files
ops: Support NodePort and InitContainers in Helm Charts (#22)
* ops: Support setting NodePort in helm charts * ops: In helm support initContainer for model download on startup
1 parent 026ce75 commit c1bc5d7

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ spec:
5454
- name: "{{ tpl $key $ }}"
5555
value: "{{ tpl (print $value) $ }}"
5656
{{- end }}
57+
{{- if .Values.model.downloadUrl }}
58+
# Note this overrides any previous env setting if downloading is enabled
59+
- name: "APP_MEDCAT_MODEL_PACK"
60+
value: "/models/{{ .Values.model.name}}"
61+
{{- end}}
5762
{{- with .Values.livenessProbe }}
5863
livenessProbe:
5964
{{- toYaml . | nindent 12 }}
@@ -70,13 +75,47 @@ spec:
7075
resources:
7176
{{- toYaml . | nindent 12 }}
7277
{{- end }}
73-
{{- with .Values.volumeMounts }}
78+
{{- if or .Values.model.downloadUrl .Values.volumeMounts }}
7479
volumeMounts:
75-
{{- toYaml . | nindent 12 }}
80+
{{- if .Values.volumeMounts }}
81+
{{- toYaml .Values.volumeMounts | nindent 2 }}
82+
{{- end }}
83+
{{- if .Values.model.downloadUrl }}
84+
- name: models
85+
mountPath: /models
86+
{{- end }}
7687
{{- end }}
77-
{{- with .Values.volumes }}
88+
{{- if .Values.model.downloadUrl }}
89+
initContainers:
90+
- name: model-downloader
91+
image: busybox:1.28
92+
command:
93+
- sh
94+
- -c
95+
- |
96+
echo "Downloading model $MODEL_NAME from $MODEL_PACK_URL"
97+
mkdir -p /models
98+
wget -O "/models/$MODEL_NAME" "$MODEL_PACK_URL"
99+
echo "Download finished"
100+
env:
101+
- name: MODEL_PACK_URL
102+
value: {{ .Values.model.downloadUrl}}
103+
- name: MODEL_NAME
104+
value: {{ .Values.model.name}}
105+
volumeMounts:
106+
- name: models
107+
mountPath: /models
108+
{{- end }}
109+
110+
{{- if or .Values.model.downloadUrl .Values.volumes }}
78111
volumes:
79-
{{- toYaml . | nindent 8 }}
112+
{{- if .Values.volumes }}
113+
{{- toYaml .Values.volumes | nindent 2 }}
114+
{{- end }}
115+
{{- if .Values.model.downloadUrl }}
116+
- name: models
117+
emptyDir: {}
118+
{{- end }}
80119
{{- end }}
81120
{{- with .Values.nodeSelector }}
82121
nodeSelector:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ spec:
1111
targetPort: http
1212
protocol: TCP
1313
name: http
14+
{{- if (and (eq .Values.service.type "NodePort") ( .Values.service.nodePort)) }}
15+
nodePort: {{ .Values.service.nodePort }}
16+
{{- end }}
1417
selector:
1518
{{- include "medcat-service.selectorLabels" . | nindent 4 }}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ env:
3131
# DEID_MODE: true
3232
# DEID_REDACT: true
3333

34+
# Enable downloading of public models using wget on startup. Model will be downloaded to /models/<name> and used for APP_MEDCAT_MODEL_PACK
35+
# model:
36+
# Public URL to download a model pack from
37+
# downloadUrl: "http://localhost:9000/models/my-model.zip"
38+
# Name of the model pack to save to. Will be stored at /models/<name>
39+
# name: my-model.zip
40+
3441
# This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
3542
imagePullSecrets: []
3643
# This is to override the chart name.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ spec:
2727
type: {{ .Values.service.type }}
2828
ports:
2929
- port: {{ .Values.service.port }}
30+
{{- if (and (eq .Values.service.type "NodePort") ( .Values.service.nodePort)) }}
31+
nodePort: {{ .Values.service.nodePort }}
32+
{{- end }}
3033
targetPort: http
3134
protocol: TCP
3235
name: http

0 commit comments

Comments
 (0)