diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/NOTES.txt b/deployment/kubernetes/charts/medcat-trainer-helm/templates/NOTES.txt index fcfca0d..b61c086 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/NOTES.txt +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/NOTES.txt @@ -15,8 +15,8 @@ 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}") + 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}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[?(@.name==\"nginx\")].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 }} diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/ingress.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/ingress.yaml index f8d3382..e2fc0dd 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/ingress.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/ingress.yaml @@ -35,7 +35,7 @@ spec: {{- end }} backend: service: - name: {{ include "medcat-trainer-helm.fullname" $ }}-nginx + name: {{ include "medcat-trainer-helm.fullname" $ }}-medcat-trainer port: number: {{ $.Values.service.port }} {{- end }} diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-configmap.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-configmap.yaml index a9eed8c..96eb40b 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-configmap.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-configmap.yaml @@ -17,7 +17,7 @@ data: pidfile=/var/run/supervisord.pid [program:medcattrainer] - command=sh -c "exec /home/scripts/run.sh 2>&1 | sed 's/^/[medcattrainer] /'" + command=sh -c "exec /home/scripts/run.sh 2>&1 | sed -u 's/^/[medcattrainer] /'" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr @@ -25,7 +25,7 @@ data: autorestart=true [program:bg-process] - command=sh -c "exec /home/scripts/run-bg-process.sh 2>&1 | sed 's/^/[bg-process] /'" + command=sh -c "exec /home/scripts/run-bg-process.sh 2>&1 | sed -u 's/^/[bg-process] /'" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr @@ -33,7 +33,7 @@ data: autorestart=true [program:db-backup] - command=sh -c "exec cron -f -l 2 2>&1 | sed 's/^/[db-backup] /'" + command=sh -c "exec cron -f -l 2 2>&1 | sed -u 's/^/[db-backup] /'" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-deployment.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-deployment.yaml index 43392cd..6376f6c 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-deployment.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-deployment.yaml @@ -4,7 +4,6 @@ metadata: name: {{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer labels: {{- include "medcat-trainer-helm.labels" . | nindent 4 }} - app.kubernetes.io/component: medcat-trainer spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} @@ -12,7 +11,6 @@ spec: selector: matchLabels: {{- include "medcat-trainer-helm.selectorLabels" . | nindent 6 }} - app.kubernetes.io/component: medcat-trainer strategy: {{ toYaml .Values.updateStrategy | nindent 4 }} template: metadata: @@ -22,7 +20,6 @@ spec: {{- end }} labels: {{- include "medcat-trainer-helm.labels" . | nindent 8 }} - app.kubernetes.io/component: medcat-trainer {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} @@ -45,8 +42,8 @@ spec: image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - - name: http - containerPort: 8000 + - name: api + containerPort: {{ .Values.service.apiPort }} protocol: TCP args: - /usr/bin/supervisord @@ -93,6 +90,43 @@ spec: {{- with .Values.volumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} + - name: nginx + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: "{{ .Values.nginxImage.repository }}:{{ .Values.nginxImage.tag }}" + imagePullPolicy: {{ .Values.nginxImage.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + {{- with .Values.nginx.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.nginx.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - name: nginx-config + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf + - name: nginx-config + mountPath: /etc/nginx/sites-enabled/medcattrainer + subPath: sitesenabled.medcattrainer + - mountPath: /home/api/media + name: api-media + - mountPath: /home/api/static + name: api-static + {{- with .Values.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} volumes: - name: medcat-trainer-config configMap: @@ -111,6 +145,9 @@ spec: persistentVolumeClaim: claimName: {{ include "medcat-trainer-helm.fullname" . }}-api-db-backup {{- end }} + - name: nginx-config + configMap: + name: {{ include "medcat-trainer-helm.fullname" . }}-nginx-config {{- with .Values.volumes }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-env-configmap.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-env-configmap.yaml index 3da9ada..5c41e57 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-env-configmap.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-env-configmap.yaml @@ -12,6 +12,8 @@ data: DB_BACKUP_DIR: "/home/api/db-backup" DB_DIR: "/home/api/db" DB_PATH: "/home/api/db/db.sqlite3" + MCT_VERSION: {{ .Values.image.tag | default .Chart.AppVersion }} + API_URL: http://localhost:{{ .Values.service.apiPort }}/api/ {{- range $key, $value := .Values.env }} {{ $key }}: {{ $value | quote }} {{- end }} \ No newline at end of file diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-secret.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-secret.yaml index 1895b3a..25b9b31 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-secret.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/medcat-trainer-secret.yaml @@ -4,6 +4,7 @@ metadata: name: {{ include "medcat-trainer-helm.fullname" . }}-secret labels: {{- include "medcat-trainer-helm.labels" . | nindent 4 }} + app.kubernetes.io/component: medcat-trainer stringData: DB_NAME: {{ .Values.postgresql.auth.database }} DB_USER: "{{ .Values.postgresql.auth.username }}" diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-configmap.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-configmap.yaml index d705eaf..27a9ea6 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-configmap.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-configmap.yaml @@ -165,7 +165,7 @@ data: } location / { - proxy_pass http://{{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer:8000; + proxy_pass http://localhost:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-deployment.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-deployment.yaml deleted file mode 100644 index 31cf545..0000000 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/nginx-deployment.yaml +++ /dev/null @@ -1,102 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "medcat-trainer-helm.fullname" . }}-nginx - labels: - {{- include "medcat-trainer-helm.labels" . | nindent 4 }} - app.kubernetes.io/component: nginx -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.nginxReplicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "medcat-trainer-helm.selectorLabels" . | nindent 6 }} - app.kubernetes.io/component: nginx - strategy: {{ toYaml .Values.nginxUpdateStrategy | nindent 4 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "medcat-trainer-helm.labels" . | nindent 8 }} - app.kubernetes.io/component: nginx - {{- with .Values.podLabels }} - {{- toYaml . | nindent 8 }} - {{- end }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ include "medcat-trainer-helm.serviceAccountName" . }} - {{- with .Values.podSecurityContext }} - securityContext: - {{- toYaml . | nindent 8 }} - {{- end }} - containers: - - name: nginx - {{- with .Values.securityContext }} - securityContext: - {{- toYaml . | nindent 12 }} - {{- end }} - image: "{{ .Values.nginxImage.repository }}:{{ .Values.nginxImage.tag }}" - imagePullPolicy: {{ .Values.nginxImage.pullPolicy }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - {{- with .Values.nginx.livenessProbe }} - livenessProbe: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.nginx.readinessProbe }} - readinessProbe: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.resources }} - resources: - {{- toYaml . | nindent 12 }} - {{- end }} - - volumeMounts: - - name: nginx-config - mountPath: /etc/nginx/nginx.conf - subPath: nginx.conf - - name: nginx-config - mountPath: /etc/nginx/sites-enabled/medcattrainer - subPath: sitesenabled.medcattrainer - - mountPath: /home/api/media - name: api-media - - mountPath: /home/api/static - name: api-static - {{- with .Values.volumeMounts }} - {{- toYaml . | nindent 12 }} - {{- end }} - volumes: - - name: nginx-config - configMap: - name: {{ include "medcat-trainer-helm.fullname" . }}-nginx-config - - name: api-media - persistentVolumeClaim: - claimName: {{ include "medcat-trainer-helm.fullname" . }}-api-media - - name: api-static - persistentVolumeClaim: - claimName: {{ include "medcat-trainer-helm.fullname" . }}-api-static - {{- with .Values.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-trainer-helm/templates/service.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/templates/service.yaml index 799a0db..7859d82 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/templates/service.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/templates/service.yaml @@ -4,25 +4,6 @@ metadata: name: {{ include "medcat-trainer-helm.fullname" . }}-medcat-trainer labels: {{- include "medcat-trainer-helm.labels" . | nindent 4 }} - app.kubernetes.io/component: medcat-trainer -spec: - type: ClusterIP - ports: - - port: 8000 - targetPort: http - protocol: TCP - name: http - selector: - {{- include "medcat-trainer-helm.selectorLabels" . | nindent 4 }} - app.kubernetes.io/component: medcat-trainer ---- -apiVersion: v1 -kind: Service -metadata: - name: {{ include "medcat-trainer-helm.fullname" . }}-nginx - labels: - {{- include "medcat-trainer-helm.labels" . | nindent 4 }} - app.kubernetes.io/component: nginx spec: type: {{ .Values.service.type }} ports: @@ -33,7 +14,10 @@ spec: targetPort: http protocol: TCP name: http + - port: {{ .Values.service.apiPort }} + targetPort: api + protocol: TCP + name: api selector: {{- include "medcat-trainer-helm.selectorLabels" . | nindent 4 }} - app.kubernetes.io/component: nginx --- diff --git a/deployment/kubernetes/charts/medcat-trainer-helm/values.yaml b/deployment/kubernetes/charts/medcat-trainer-helm/values.yaml index a6bca47..c2d9f4e 100644 --- a/deployment/kubernetes/charts/medcat-trainer-helm/values.yaml +++ b/deployment/kubernetes/charts/medcat-trainer-helm/values.yaml @@ -9,7 +9,7 @@ replicaCount: 1 image: repository: cogstacksystems/medcat-trainer # This sets the pull policy for images. - pullPolicy: IfNotPresent + pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. tag: "latest" nginxImage: @@ -33,6 +33,7 @@ env: OPENBLAS_NUM_THREADS: "1" RESUBMIT_ALL_ON_STARTUP: "0" UNIQUE_DOC_NAMES_IN_DATASETS: "True" + VITE_USE_OIDC: "0" # TODO: Support custom DB overrides# # DB_ENGINE: "sqlite3" @@ -162,8 +163,10 @@ 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: 8000 - + port: 8001 + apiPort: 8000 # Note medcat-trainer API is currently hardcoded on 8000 in the run.sh script + # nodePort: 30001 + # 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 @@ -188,27 +191,28 @@ resources: {} # lines, adjust them as necessary, and remove the curly braces after 'resources:'. # limits: # cpu: 3 # Recommended to leave unset. If desired to set note service performance has been found to improve up to around 3 CPU. - # memory: 2Gi + # memory: 4Gi # requests: - # cpu: 1 - # memory: 1Gi + # cpu: 2 # For reference loading the examples on startup measured to use 2CPU and 2Gi memory + # memory: 2Gi # 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 + path: /api/health/live/?format=json + port: api + failureThreshold: 30 readinessProbe: httpGet: - path: /api/health/ready/ - port: http + path: /api/health/ready/?format=json + port: api startupProbe: httpGet: - path: /api/health/startup/ - port: http + path: /api/health/startup/?format=json + port: api failureThreshold: 30 periodSeconds: 10 - initialDelaySeconds: 5 + initialDelaySeconds: 15 nginx: livenessProbe: diff --git a/deployment/kubernetes/local_dev_startup.sh b/deployment/kubernetes/local_dev_startup.sh index 6347bb1..f4c22b6 100644 --- a/deployment/kubernetes/local_dev_startup.sh +++ b/deployment/kubernetes/local_dev_startup.sh @@ -21,7 +21,7 @@ helm test medcat-service --logs # Test medcat trainer # kubectl port-forward svc/nginx 8000:8000 -helm upgrade my-test ./medcat-trainer-helm --install --recreate-pods --wait --timeout 5m0s # Install if it doesnt already exist, else upgrade +helm upgrade x ./medcat-trainer-helm --install --wait --timeout 5m0s # Install if it doesnt already exist, else upgrade # kubectl port-forward svc/medcat-trainer-solr 8983:8983 ## helm install trainer-registry oci://registry-1.docker.io/cogstacksystems/medcat-trainer-helm --wait --timeout 5m0s