# MedCAT Trainer Helm Chart for Kubernetes

**URL:** <https://discourse.cogstack.org/t/medcat-trainer-helm-chart-for-kubernetes/175>\
**Category:** MedCAT\
**Created:** [March 20, 2023, 12:32pm UTC](https://discourse.cogstack.org/t/medcat-trainer-helm-chart-for-kubernetes/175 "2023-03-20T12:32:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vvcb](https://avatars.discourse-cdn.com/v4/letter/v/50afbb/32.png) [@vvcb](https://discourse.cogstack.org/u/vvcb)\
**Post date:** [March 20, 2023, 12:32pm UTC](https://discourse.cogstack.org/t/medcat-trainer-helm-chart-for-kubernetes/175/1 "2023-03-20T12:32:03Z")

</div>

Hi All,

Our analytics infrastructure is hosted on Microsoft Azure and a large part of it is deployed to Azure Kubernetes Service (AKS).

I have been working on a scalable deployment of MedCAT for annotation on AKS as noted in a [previous post](https://discourse.cogstack.org/t/hardware-cloud-requirements-for-real-world-hospital-cogstack-nifi-deployment/33/3).

It made sense to also be able to deploy [MedCAT Trainer](https://github.com/CogStack/MedCATtrainer) on AKS. I was unable to find a Helm chart and so have started working on one.

> **[GitHub - LTHTR-DST/medcat\_trainer\_helm: Helm Chart for deploying...](https://github.com/LTHTR-DST/medcat_trainer_helm)**
>
> Helm Chart for deploying https://github.com/CogStack/MedCATtrainer on Kubernetes - GitHub - LTHTR-DST/medcat\_trainer\_helm: Helm Chart for deploying https://github.com/CogStack/MedCATtrainer on Kube...

At the time of writing this post, this is the status:

- SOLR pod works and the UI is reachable through port-forwarding
- NGINX pod crashes with error messages as below. Looks like the nginx container is heavily customised and I wonder if it is just possible to use k8s nginx controller with modifications. I will explore this further when I get a chance.
- MedCATTrainer pod does not pull the image successfully yet. But, seeing that the image pulled successfully to my laptop when using docker-compose, I suspect that this may simply be a timeout issue and should be easy enough to fix.

**NGINX error message**

```shell
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/03/20 12:20:34 [emerg] 1#1: host not found in upstream "mct_solr" in /etc/nginx/sites-enabled/medcattrainer:17
nginx: [emerg] host not found in upstream "mct_solr" in /etc/nginx/sites-enabled/medcattrainer:17

```

_ **If someone has already built a working version, please let me know before I travel too far down this rabbit hole.** _

Else I will post updates as I go along. Contributions welcome.

---

<div class="post-metadata">

**Author:** ![vvcb](https://avatars.discourse-cdn.com/v4/letter/v/50afbb/32.png) [@vvcb](https://discourse.cogstack.org/u/vvcb)\
**Post date:** [March 20, 2023, 1:08pm UTC](https://discourse.cogstack.org/t/medcat-trainer-helm-chart-for-kubernetes/175/2 "2023-03-20T13:08:31Z")

</div>

MedCAT Trainer also starts up successfully.

But, with no exposed port, not sure how the other pods talk to this pod.

[`docker-compose.yml`](https://github.com/CogStack/MedCATtrainer/blob/master/docker-compose.yml) does not specify a port for `medcattrainer` while [`docker-compose-prod.yml`](https://github.com/CogStack/MedCATtrainer/blob/master/docker-compose-prod.yml) and [`docker-compose-mc0x.yml`](https://github.com/CogStack/MedCATtrainer/blob/master/docker-compose-mc0x.yml) both expose port 8000.

I have created a new k8s service with port 8000 exposed on the MedCATTrainer pod and portforwarding this but results in the following blank webpage.

```html
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="icon" href="/favicon.ico">
    <title>MedCATTrainer</title>
    <link href="/static/css/app.5980f582.css" rel="preload" as="style">
    <link href="/static/css/chunk-vendors.6879fd7c.css" rel="preload" as="style">
    <link href="/static/js/app.15921033.js" rel="preload" as="script">
    <link href="/static/js/chunk-vendors.83ec4c01.js" rel="preload" as="script">
    <link href="/static/css/chunk-vendors.6879fd7c.css" rel="stylesheet">
    <link href="/static/css/app.5980f582.css" rel="stylesheet">
</head>

<body><noscript><strong>We're sorry but MedCATTrainer doesn't work properly without JavaScript enabled. Please enable it
            to continue.</strong></noscript>
    <div id="app"></div>
    <script src="/static/js/chunk-vendors.83ec4c01.js"></script>
    <script src="/static/js/app.15921033.js"></script>
</body>

</html>

```

Any advice from the MedCAT team will be helpful. I suspect the `mct_solr` service hard-coded in the nginx container may have something to do with all of this.

But, hey, I have 2 out of 3 working. 🙂

---

<div class="post-metadata">

**Author:** ![tomolopolis](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@tomolopolis](https://discourse.cogstack.org/u/tomolopolis)\
**Post date:** [March 23, 2023, 10:20am UTC](https://discourse.cogstack.org/t/medcat-trainer-helm-chart-for-kubernetes/175/3 "2023-03-23T10:20:41Z")

</div>

Hi @vvcb - thanks for the contribution great stuff!

the MCTrainer API (django server) is mapped on the [nginx config to ‘/’ on port 8000](https://github.com/CogStack/MedCATtrainer/blob/master/nginx/sites-enabled/medcattrainer#L24), via the docker-compose service name, i.e. ‘medcattrainer’.

The custom nginx image probably isn’t needed here, as its really just a sites-enabled and static-content mount which could be performed at runtime not build time. Hoping to get around to looking into this soon.

The nginx service is exposed externally to [8001 and mapped to 8000](https://github.com/CogStack/MedCATtrainer/blob/master/docker-compose.yml#L28)

Hope that helps!

---

<div class="post-metadata">

**Author:** ![vvcb](https://avatars.discourse-cdn.com/v4/letter/v/50afbb/32.png) [@vvcb](https://discourse.cogstack.org/u/vvcb)\
**Post date:** [March 28, 2023, 10:15am UTC](https://discourse.cogstack.org/t/medcat-trainer-helm-chart-for-kubernetes/175/4 "2023-03-28T10:15:50Z")

</div>

Thanks @tomolopolis .

I now have a working Helm chart that deploys to AKS and most things appear to work.

Details here → [Release v0.0.1 · LTHTR-DST/medcat\_trainer\_helm · GitHub](https://github.com/LTHTR-DST/medcat_trainer_helm/releases/tag/v0.0.1)

It took me a little while to figure out that the nginx container was acting as both ingress controller and static content server. I think I have successfully separated these functions and have moved the [ingress control function](https://github.com/LTHTR-DST/medcat_trainer_helm/blob/main/templates/ingress.yaml) to the Kubernetes nginx-ingress controller that I already have deployed in the cluster.

There is still a lot of tidying up to do including serving this from a subpath of a host domain.

@tomolopolis , MedCATtrainer uses sqlite3 behind the scenes. I have simulated 2 users annotating simultaneously (1 in incognito mode) and it seems to work. If this is the case, this is a really useful feature. Does MedCATTrainer support multiple simultaneous users _out-of-the-box._

If we have several people annotating at the same time, then will be useful to leverage some of k8s autoscaling features. However, I don’t think there is an immediate use case for this yet - don’t think anyone has an army of annotators at their disposal!
