Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/kubernetes-charts-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ jobs:
uses: actions/checkout@v5

- name: Package Helm Charts
run: helm package ./charts/medcat-service-helm --version $CHART_VERSION
run: |
helm package ./charts/medcat-service-helm --version $CHART_VERSION
helm package ./charts/medcat-trainer-helm --version $CHART_VERSION --dependency-update

- name: Helm OCI login to Docker Hub
run: helm registry login registry-1.docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push Helm Chart to Docker Hub OCI
run: |
helm push ./medcat-service-helm-${CHART_VERSION}.tgz oci://registry-1.docker.io/cogstacksystems
helm push ./medcat-trainer-helm-${CHART_VERSION}.tgz oci://registry-1.docker.io/cogstacksystems
23 changes: 23 additions & 0 deletions deployment/kubernetes/charts/medcat-trainer-helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
9 changes: 9 additions & 0 deletions deployment/kubernetes/charts/medcat-trainer-helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: solr
repository: oci://registry-1.docker.io/bitnamicharts
version: 9.6.10
- name: postgresql
repository: oci://registry-1.docker.io/bitnamicharts
version: 16.7.27
digest: sha256:a02db326b15b24d92e4c0787792803d7b224babd4f288e28a73d66a7d4506a70
generated: "2025-09-10T11:29:31.705470067Z"
34 changes: 34 additions & 0 deletions deployment/kubernetes/charts/medcat-trainer-helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: v2
name: medcat-trainer-helm
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "latest"

# Chart.yaml
dependencies:
- name: solr
version: "9.6.10"
repository: "oci://registry-1.docker.io/bitnamicharts"
- name: postgresql
version: 16.7.27
repository: "oci://registry-1.docker.io/bitnamicharts"
condition: postgresql.enabled
49 changes: 49 additions & 0 deletions deployment/kubernetes/charts/medcat-trainer-helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# MedCAT Trainer Helm Chart

This Helm chart deploys MedCAT Trainer and infrastructure to a Kubernetes cluster.

By default the chart will:

- Run MedCAT Trainer Django server
- Run NGINX for static site hosting and routing
- Run a SOLR and Zookeeper cluster for the Concept DB
- Run a Postgres database for persistence


## Installation

```sh
helm install my-medcat-trainer oci://registry-1.docker.io/cogstacksystems/medcat-trainer-helm
```

## Configuration

See these values for common configurations to change:

| Setting |description |
| -------- | -------- |
| `env` | Environment variables as defined in the [MedCAT Trainer docs](https://docs.cogstack.org/projects/medcat-trainer/en/latest/installation.html). |
|`medcatConfig`|MedCAT config file as described [here](https://github.com/CogStack/cogstack-nlp/blob/main/medcat-v2/medcat/config/config.py)|
| `env.CSRF_TRUSTED_ORIGINS` | The Host and Port to access the application on |


### Use Sqlite instead of Postgres

Sqlite can be used for smaller single instance deployments

Set these values:

```yaml
DB_ENGINE: "sqlite3"

postgresql:
enabled: false
```

## Missing features
These features are not yet existing but to be added in future:
- Use a pre existing postgres db
- Use a pre existing SOLR instance
- Migrate from supervisord to standalone deployment for background tasks for better scaling
- Support SOLR authentication from medcat trainer
- Support passing DB OPTIONS to medcat trainer for use in cloud environments
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "medcat-trainer-helm.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "medcat-trainer-helm.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "medcat-trainer-helm.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
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}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "medcat-trainer-helm.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "medcat-trainer-helm.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "medcat-trainer-helm.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "medcat-trainer-helm.labels" -}}
helm.sh/chart: {{ include "medcat-trainer-helm.chart" . }}
{{ include "medcat-trainer-helm.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: cogstack
{{- end }}

{{/*
Selector labels
*/}}
{{- define "medcat-trainer-helm.selectorLabels" -}}
app.kubernetes.io/name: {{ include "medcat-trainer-helm.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "medcat-trainer-helm.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "medcat-trainer-helm.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}


{{- /*
Return Solr host: either user-supplied or constructed from release name

TODO: Make Solr use the chart fullname instead of release name
*/ -}}
{{- define "medcat-trainer-helm.solrHost" -}}
{{- if .Values.solrHost }}
{{ .Values.solrHost }}
{{- else }}
{{- .Release.Name }}-solr
{{- end }}
{{- end }}

{{- /*
Return Solr port: either user-supplied or default from values
*/ -}}
{{- define "medcat-trainer-helm.solrPort" -}}
{{- if .Values.solrPort }}
{{ .Values.solrPort }}
{{- else }}
{{- .Values.solr.service.ports.http }}
{{- end }}
{{- end }}

{{- /*
Return full Solr URL: combines host and port
*/ -}}
{{- define "medcat-trainer-helm.solrURL" -}}
http://{{ include "medcat-trainer-helm.solrHost" . }}:{{ include "medcat-trainer-helm.solrPort" . }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "medcat-trainer-helm.fullname" . }}
labels:
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "medcat-trainer-helm.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "medcat-trainer-helm.fullname" . }}
labels:
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.ingress.className }}
ingressClassName: {{ . }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- with .pathType }}
pathType: {{ . }}
{{- end }}
backend:
service:
name: {{ include "medcat-trainer-helm.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer-config
labels:
{{- include "medcat-trainer-helm.labels" . | nindent 4 }}
app.kubernetes.io/component: medcat-trainer
data:
# This is mounted in the path for MEDCAT_CONFIG_FILE in the backend. Default to /home/configs/base.txt
medcat-base.txt: |
{{ .Values.medcatConfig | indent 4 }}
supervisord.conf: |
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

[program:medcattrainer]
command=sh -c "exec /home/scripts/run.sh 2>&1 | sed 's/^/[medcattrainer] /'"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true

[program:bg-process]
command=sh -c "exec /home/scripts/run-bg-process.sh 2>&1 | sed 's/^/[bg-process] /'"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true

[program:db-backup]
command=sh -c "exec cron -f -l 2 2>&1 | sed 's/^/[db-backup] /'"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
Loading
Loading