diff --git a/.github/workflows/kubernetes-charts-build.yaml b/.github/workflows/kubernetes-charts-build.yaml new file mode 100644 index 0000000..88a372f --- /dev/null +++ b/.github/workflows/kubernetes-charts-build.yaml @@ -0,0 +1,80 @@ +name: Kubernetes - Lint, Test, and Publish Helm Charts + +on: pull_request +defaults: + run: + working-directory: ./deployment/kubernetes + + +jobs: + helm-lint-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + with: + version: v3.17.0 + + - uses: actions/setup-python@v5.3.0 + with: + python-version: '3.x' + check-latest: true + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.7.0 + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch}}) + if [[ -n "$changed" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + + - name: Run chart-testing (lint) + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --target-branch ${{ github.event.repository.default_branch }} + + - name: Create kind cluster + if: steps.list-changed.outputs.changed == 'true' + uses: helm/kind-action@v1.12.0 + + - name: Run chart-testing (install) + if: steps.list-changed.outputs.changed == 'true' + run: ct install --target-branch ${{ github.event.repository.default_branch }} + + helm-publish: + runs-on: ubuntu-latest + needs: helm-lint-test + env: + CHART_VERSION: 0.0.1 + steps: + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + with: + version: v3.17.0 + + - name: Checkout + uses: actions/checkout@v5 + + - name: Package Helm Charts + run: helm package ./charts/medcat-service-helm --version $CHART_VERSION + + - 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 diff --git a/README.md b/README.md index 0a31e50..5896e5d 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,5 @@ See the latest documentation on [Readthedocs](https://docs.cogstack.org/en/lates ## Project contents - Source for the official cogstack documentation. This git repo stores the top level documetation that hosts on https://docs.cogstack.org - CogStack deployment instructions and examples +- Helm Charts for deployments - CogStack platform tools eg Observability. diff --git a/deployment/kubernetes/charts/.gitignore b/deployment/kubernetes/charts/.gitignore new file mode 100644 index 0000000..84bcc20 --- /dev/null +++ b/deployment/kubernetes/charts/.gitignore @@ -0,0 +1,3 @@ + +# Ignore packaged helm charts +*.tgz \ No newline at end of file diff --git a/deployment/kubernetes/charts/medcat-service-helm/.helmignore b/deployment/kubernetes/charts/medcat-service-helm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/.helmignore @@ -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/ diff --git a/deployment/kubernetes/charts/medcat-service-helm/Chart.yaml b/deployment/kubernetes/charts/medcat-service-helm/Chart.yaml new file mode 100644 index 0000000..418fa78 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/Chart.yaml @@ -0,0 +1,30 @@ +apiVersion: v2 +name: medcat-service-helm +description: A Helm chart to deploy CogStack medcat-service + +# 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" + +maintainers: + - name: alhendrickson + email: alistair@cogstack.org + +icon: "https://avatars.githubusercontent.com/u/28688163" diff --git a/deployment/kubernetes/charts/medcat-service-helm/README.md b/deployment/kubernetes/charts/medcat-service-helm/README.md new file mode 100644 index 0000000..68fba10 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/README.md @@ -0,0 +1,62 @@ +# MedCAT Service Helm Chart + +This Helm chart deploys the MedCAT service to a Kubernetes cluster. + +## Installation + +```sh +helm install my-medcat-service oci://registry-1.docker.io/cogstacksystems/medcat-service-helm +``` + +## Configuration + +You should specify a model pack to be used by the service. By default it will use a small bundled model, which can be used for testing + +--- +### Option 1: Use the demo model pack + +There is a model pack already bundled into medcat service, and is the default in this chart. + +This pack is only really used for testing, and has just a few concepts built in. + +### Option 2: Download Model on Startup + +Enable MedCAT to download the model from a remote URL on container startup. + +Create a values file like `values-model-download.yaml` and update the env vars with: +```yaml +env: + ENABLE_MODEL_DOWNLOAD: "true" + MODEL_NAME: "medmen" + MODEL_VOCAB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/vocab.dat" + MODEL_CDB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/cdb-medmen-v1.dat" + MODEL_META_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/mc_status.zip" + APP_MODEL_CDB_PATH: "/cat/models/medmen/cdb.dat" +``` + +Use this if you prefer dynamic loading of models at runtime. + +### Option 3: Get a model into a k8s volume, and mount it + +The service can use a model pack if you want to setup your own download flow. For example, setup an initContainer pattern that downloads to a volume, then mount the volume yourself. + +Use this env variable to point to the file: + +Create a values file like `values-model-pack.yaml` and update the env vars with: +```yaml +env: + # This defines the Model Pack used by the medcat service + APP_MEDCAT_MODEL_PACK: "/cat/models/examples/example-medcat-v1-model-pack.zip" +``` + +## Example + +```sh +helm install my-medcat ./medcat-chart -f values-model-pack.yaml +``` + +or + +```sh +helm install my-medcat ./medcat-chart -f values-model-download.yaml +``` diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/NOTES.txt b/deployment/kubernetes/charts/medcat-service-helm/templates/NOTES.txt new file mode 100644 index 0000000..3b07139 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/NOTES.txt @@ -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-service.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-service.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "medcat-service.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-service.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -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 --pod-running-timeout=5m0s +{{- end }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/_helpers.tpl b/deployment/kubernetes/charts/medcat-service-helm/templates/_helpers.tpl new file mode 100644 index 0000000..d640db0 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/_helpers.tpl @@ -0,0 +1,63 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "medcat-service.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-service.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-service.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "medcat-service.labels" -}} +helm.sh/chart: {{ include "medcat-service.chart" . }} +{{ include "medcat-service.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-service.selectorLabels" -}} +app.kubernetes.io/name: {{ include "medcat-service.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "medcat-service.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "medcat-service.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/deployment.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/deployment.yaml new file mode 100644 index 0000000..f4f32e5 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/deployment.yaml @@ -0,0 +1,92 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "medcat-service.fullname" . }} + labels: + {{- include "medcat-service.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "medcat-service.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "medcat-service.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "medcat-service.serviceAccountName" . }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + env: + {{- range $key, $value := .Values.envValueFrom }} + - name: {{ $key | quote }} + valueFrom: + {{- tpl (toYaml $value) $ | nindent 10 }} + {{- end }} + {{- range $key, $value := .Values.env }} + - name: "{{ tpl $key $ }}" + value: "{{ tpl (print $value) $ }}" + {{- end }} + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.startupProbe }} + startupProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/hpa.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/hpa.yaml new file mode 100644 index 0000000..82c086f --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "medcat-service.fullname" . }} + labels: + {{- include "medcat-service.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "medcat-service.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 }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/ingress.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/ingress.yaml new file mode 100644 index 0000000..58a250a --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/ingress.yaml @@ -0,0 +1,45 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "medcat-service.fullname" . }} + labels: + {{- include "medcat-service.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.http }} + - {{- if .host }} + host: {{ .host | quote }} + {{- end }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: {{ include "medcat-service.fullname" $ }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/service.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/service.yaml new file mode 100644 index 0000000..9eee849 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "medcat-service.fullname" . }} + labels: + {{- include "medcat-service.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "medcat-service.selectorLabels" . | nindent 4 }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/serviceaccount.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/serviceaccount.yaml new file mode 100644 index 0000000..f3c5b71 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "medcat-service.serviceAccountName" . }} + labels: + {{- include "medcat-service.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/tests/test-acceptance.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/tests/test-acceptance.yaml new file mode 100644 index 0000000..f8048c4 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/tests/test-acceptance.yaml @@ -0,0 +1,46 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "medcat-service.fullname" . }}-test-acceptance" + labels: + {{- include "medcat-service.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test + "helm.sh/hook-weight": "2" +spec: + containers: + - name: curl-test + image: curlimages/curl:latest + securityContext: + runAsUser: 0 + command: ["/bin/sh", "-c"] + args: + - | + set -e + apk add --no-cache jq + + + api="{{ include "medcat-service.fullname" . }}:{{ .Values.service.port }}/api/process" + input_text="The patient was diagnosed with Kidney Failure" + input_payload="{\"content\":{\"text\":\"${input_text}\"}}" + expected_annotation="Kidney Failure" + + echo "Calling POST $api with payload '$input_payload'" + actual=$(curl -s -X POST "$api" \ + -H 'Content-Type: application/json' \ + --user-agent 'helm-test {{ .Chart.Name }}-v{{ .Chart.Version }}' \ + -d "$input_payload") + + echo "Received result '$actual'" + + actual_annotation=$(echo "$actual" | jq -r '.result.annotations[0]["0"].pretty_name') + echo "Expected Annotation is '${expected_annotation}'. Actual Annotation is '${actual_annotation}'" + + if [ "$actual_annotation" = "$expected_annotation" ]; then + echo "Service working and extracting annotations" + else + echo "Expected: $expected_annotation, Got: $actual_annotation" + echo -e "Actual response was:\n${actual}" + exit 1 + fi + restartPolicy: Never \ No newline at end of file diff --git a/deployment/kubernetes/charts/medcat-service-helm/templates/tests/test-connection.yaml b/deployment/kubernetes/charts/medcat-service-helm/templates/tests/test-connection.yaml new file mode 100644 index 0000000..d61e647 --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/templates/tests/test-connection.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "medcat-service.fullname" . }}-test-connection" + labels: + {{- include "medcat-service.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test + "helm.sh/hook-weight": "1" +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "medcat-service.fullname" . }}:{{ .Values.service.port }}/api/health/live', '-U helm-test {{ .Chart.Name }}-v{{ .Chart.Version }}'] + restartPolicy: Never diff --git a/deployment/kubernetes/charts/medcat-service-helm/values.yaml b/deployment/kubernetes/charts/medcat-service-helm/values.yaml new file mode 100644 index 0000000..0cfa56b --- /dev/null +++ b/deployment/kubernetes/charts/medcat-service-helm/values.yaml @@ -0,0 +1,146 @@ +# Default values for medcat-service. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/ +replicaCount: 1 + +# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ +image: + repository: cogstacksystems/medcat-service + # This sets the pull policy for images. + # pullPolicy: IfNotPresent + pullPolicy: Always + # Overrides the image tag whose default is the chart appVersion. + # tag: "latest" + +env: + # This defines the Model Pack used by the medcat service + APP_MEDCAT_MODEL_PACK: "/cat/models/examples/example-medcat-v2-model-pack.zip" + + # Alternatively download a model on startup from a URL + # ENABLE_MODEL_DOWNLOAD: "true" + # MODEL_NAME: "medmen" + # MODEL_VOCAB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/vocab.dat" + # MODEL_CDB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/cdb-medmen-v1.dat" + # MODEL_META_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/mc_status.zip" + # APP_MODEL_CDB_PATH: "/cat/models/medmen/cdb.dat" + +# 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/ +imagePullSecrets: [] +# This is to override the chart name. +nameOverride: "" +fullnameOverride: "" + +# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +# This is for setting Kubernetes Annotations to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +podAnnotations: {} +# This is for setting Kubernetes Labels to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ +service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 5000 + +# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/ +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + http: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + # Allows global ingress without hostname, matching all calls to the host. + - paths: + - path: /medcat-service + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +# 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/ +livenessProbe: + httpGet: + path: /api/health/live + port: http +readinessProbe: + httpGet: + path: /api/health/ready + port: http +startupProbe: + httpGet: + path: /api/health/ready + port: http + failureThreshold: 30 + periodSeconds: 10 + +# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/deployment/kubernetes/local_dev_startup.sh b/deployment/kubernetes/local_dev_startup.sh new file mode 100644 index 0000000..b4999ee --- /dev/null +++ b/deployment/kubernetes/local_dev_startup.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +minikube start +minikube addons enable metrics-server + +minikube dashboard --url=true & + +helm upgrade medcat-service ./medcat-service-helm --install --recreate-pods --wait --timeout 5m0s # Install if it doesnt already exist, else upgrade + +helm test medcat-service --logs + +# Run CT Lint +# docker run -it --network host --workdir=/data --volume ~/.kube/config:/root/.kube/config:ro --volume $(pwd):/data quay.io/helmpack/chart-testing:v3.7.1 ct lint --chart-dirs . --charts . + +# Helm Install from Docker Hub +# helm install my-medcat oci://registry-1.docker.io/cogstacksystems/medcat-service-helm --wait --timeout 5m0s + +# Test with host header set for ingress routing +# HOST_IP=10.211.112.82 +# curl --resolve chart-example.local:80:${HOST_IP} http://chart-example.local/api/info \ No newline at end of file diff --git a/docs/platform/deployment/helm/_index.md b/docs/platform/deployment/helm/_index.md index ce83ae8..f2ae6e5 100644 --- a/docs/platform/deployment/helm/_index.md +++ b/docs/platform/deployment/helm/_index.md @@ -14,7 +14,7 @@ To understand how the Helm charts are structured and how they work under the hoo :maxdepth: 2 tutorial -architecture cogstack-helm-module +charts/_index ``` diff --git a/docs/platform/deployment/helm/architecture.md b/docs/platform/deployment/helm/charts/_index.md similarity index 64% rename from docs/platform/deployment/helm/architecture.md rename to docs/platform/deployment/helm/charts/_index.md index 41f0e91..fe202c8 100644 --- a/docs/platform/deployment/helm/architecture.md +++ b/docs/platform/deployment/helm/charts/_index.md @@ -1,14 +1,17 @@ -# Architecture - -## Charts +# Cogstack Helm Charts The Helm charts for CogStack are published to Docker Hub, which is an OCI-compliant registry. -### Chart Listings +## Chart Listings - **MedCAT Service:** https://hub.docker.com/r/cogstacksystems/medcat-service-helm -### Chart Publishing +```{toctree} +:maxdepth: 1 +medcat-service-helm +``` + +## Chart Publishing -Charts are published automatically via a GitHub Action on every commit to the main branch. \ No newline at end of file +Charts are published automatically via a GitHub Action on every commit to the main branch. diff --git a/docs/platform/deployment/helm/charts/medcat-service-helm.md b/docs/platform/deployment/helm/charts/medcat-service-helm.md new file mode 100644 index 0000000..68fba10 --- /dev/null +++ b/docs/platform/deployment/helm/charts/medcat-service-helm.md @@ -0,0 +1,62 @@ +# MedCAT Service Helm Chart + +This Helm chart deploys the MedCAT service to a Kubernetes cluster. + +## Installation + +```sh +helm install my-medcat-service oci://registry-1.docker.io/cogstacksystems/medcat-service-helm +``` + +## Configuration + +You should specify a model pack to be used by the service. By default it will use a small bundled model, which can be used for testing + +--- +### Option 1: Use the demo model pack + +There is a model pack already bundled into medcat service, and is the default in this chart. + +This pack is only really used for testing, and has just a few concepts built in. + +### Option 2: Download Model on Startup + +Enable MedCAT to download the model from a remote URL on container startup. + +Create a values file like `values-model-download.yaml` and update the env vars with: +```yaml +env: + ENABLE_MODEL_DOWNLOAD: "true" + MODEL_NAME: "medmen" + MODEL_VOCAB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/vocab.dat" + MODEL_CDB_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/cdb-medmen-v1.dat" + MODEL_META_URL: "https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/mc_status.zip" + APP_MODEL_CDB_PATH: "/cat/models/medmen/cdb.dat" +``` + +Use this if you prefer dynamic loading of models at runtime. + +### Option 3: Get a model into a k8s volume, and mount it + +The service can use a model pack if you want to setup your own download flow. For example, setup an initContainer pattern that downloads to a volume, then mount the volume yourself. + +Use this env variable to point to the file: + +Create a values file like `values-model-pack.yaml` and update the env vars with: +```yaml +env: + # This defines the Model Pack used by the medcat service + APP_MEDCAT_MODEL_PACK: "/cat/models/examples/example-medcat-v1-model-pack.zip" +``` + +## Example + +```sh +helm install my-medcat ./medcat-chart -f values-model-pack.yaml +``` + +or + +```sh +helm install my-medcat ./medcat-chart -f values-model-download.yaml +```