From 917a9a23ec8b27bd826caa752cc136db376c1d34 Mon Sep 17 00:00:00 2001 From: Chris Nicolaescu Date: Mon, 31 Jul 2023 12:29:12 +0100 Subject: [PATCH 01/11] Containerised branch and added Dockerfile --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ff7862a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9 + +WORKDIR /app + +COPY ./API /app + +RUN python3 -m pip install -r requirements.txt + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] From 4305c6ec44697958e96e4374f265bd3571993239 Mon Sep 17 00:00:00 2001 From: Chris Nicolaescu Date: Fri, 18 Aug 2023 10:52:18 +0100 Subject: [PATCH 02/11] Added static and gitkeep --- Dockerfile | 9 --------- src/static/.gitkeep | 0 2 files changed, 9 deletions(-) delete mode 100644 Dockerfile create mode 100644 src/static/.gitkeep diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index ff7862a..0000000 --- a/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM python:3.9 - -WORKDIR /app - -COPY ./API /app - -RUN python3 -m pip install -r requirements.txt - -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/src/static/.gitkeep b/src/static/.gitkeep new file mode 100644 index 0000000..e69de29 From 6b097668b9d035fea13fa3a717e73202dd055177 Mon Sep 17 00:00:00 2001 From: Chris Nicolaescu Date: Fri, 18 Aug 2023 10:53:08 +0100 Subject: [PATCH 03/11] Added static and gitkeep --- Dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..79cdca4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.9 + +COPY ./src /app/src +COPY requirements.txt /app + +RUN pip3 install -r /app/requirements.txt + +WORKDIR /app/src + +EXPOSE 3001 + +CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--port=3001"] \ No newline at end of file From 55b8fc8d7a75e59e34052119eca00831999d37f5 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 21 Feb 2024 11:55:35 +0000 Subject: [PATCH 04/11] Added mini-api-pod.yaml --- mini-api-pod.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 mini-api-pod.yaml diff --git a/mini-api-pod.yaml b/mini-api-pod.yaml new file mode 100644 index 0000000..f48aea5 --- /dev/null +++ b/mini-api-pod.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mini-api-pod +spec: + containers: + - name: mini-api + image: harbor.patras5g.eu/5gasp/mini-api-server + command: + - "/bin/sh" + - "-c" + - "tail -f /dev/null" + From 03ae9d62e0bc247d11c4fe17ebe9839abb09a8fc Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 21 Feb 2024 16:45:29 +0000 Subject: [PATCH 05/11] Added tag to container Added the tag to container in pod definition, after re-uploading docker image to harbor --- mini-api-pod.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mini-api-pod.yaml b/mini-api-pod.yaml index f48aea5..4efcfce 100644 --- a/mini-api-pod.yaml +++ b/mini-api-pod.yaml @@ -6,6 +6,7 @@ spec: containers: - name: mini-api image: harbor.patras5g.eu/5gasp/mini-api-server + tag: latest command: - "/bin/sh" - "-c" From 5bfbafbb96b71914902862357d469509a5f44a8d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 7 Mar 2024 16:19:32 +0000 Subject: [PATCH 06/11] Added pod and service manifests Defined, deployed and tested pod and service manifests --- mini-api-pod.yaml | 9 +++++++-- mini-api-svc.yaml | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 mini-api-svc.yaml diff --git a/mini-api-pod.yaml b/mini-api-pod.yaml index 4efcfce..80f7b22 100644 --- a/mini-api-pod.yaml +++ b/mini-api-pod.yaml @@ -2,11 +2,16 @@ apiVersion: v1 kind: Pod metadata: name: mini-api-pod + labels: + app: mini-api spec: containers: - name: mini-api - image: harbor.patras5g.eu/5gasp/mini-api-server - tag: latest + image: harbor.patras5g.eu/5gasp/mini-api-server:latest-x86 + ports: + - name: http + containerPort: 3001 + protocol: TCP command: - "/bin/sh" - "-c" diff --git a/mini-api-svc.yaml b/mini-api-svc.yaml new file mode 100644 index 0000000..3588b07 --- /dev/null +++ b/mini-api-svc.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: mini-api-svc +spec: + type: NodePort + ports: + - port: 3001 + targetPort: 3001 + nodePort: 31001 + protocol: TCP + name: mini-api + selector: + app: mini-api From 4e072bb14b9c9ea05649556b730b3f65c9fb3e51 Mon Sep 17 00:00:00 2001 From: Chrisys93 Date: Fri, 8 Mar 2024 15:50:02 +0000 Subject: [PATCH 07/11] Added blame --- mini-api-pod.yaml | 13 +++++++++---- mini-api-svc.yaml | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mini-api-pod.yaml b/mini-api-pod.yaml index 80f7b22..657f972 100644 --- a/mini-api-pod.yaml +++ b/mini-api-pod.yaml @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +# @Author: Chris Nicolaescu +# @Date: 2024-01-07 +# @Last Modified by: +# @Last Modified time: apiVersion: v1 kind: Pod metadata: @@ -12,8 +17,8 @@ spec: - name: http containerPort: 3001 protocol: TCP - command: - - "/bin/sh" - - "-c" - - "tail -f /dev/null" +# command: +# - "/bin/sh" +# - "-c" +# - "tail -f /dev/null" diff --git a/mini-api-svc.yaml b/mini-api-svc.yaml index 3588b07..8f9b354 100644 --- a/mini-api-svc.yaml +++ b/mini-api-svc.yaml @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +# @Author: Chris Nicolaescu +# @Date: 2024-01-07 +# @Last Modified by: +# @Last Modified time: apiVersion: v1 kind: Service metadata: @@ -5,7 +10,7 @@ metadata: spec: type: NodePort ports: - - port: 3001 + - port: 31001 targetPort: 3001 nodePort: 31001 protocol: TCP From 2a2d6f693d940c6472456e899aba9fb20affbebb Mon Sep 17 00:00:00 2001 From: Chrisys93 Date: Wed, 13 Mar 2024 14:25:10 +0000 Subject: [PATCH 08/11] Moved manifests to k8s folder For merge --- mini-api-pod.yaml => k8s/mini-api-pod.yaml | 0 mini-api-svc.yaml => k8s/mini-api-svc.yaml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename mini-api-pod.yaml => k8s/mini-api-pod.yaml (100%) rename mini-api-svc.yaml => k8s/mini-api-svc.yaml (100%) diff --git a/mini-api-pod.yaml b/k8s/mini-api-pod.yaml similarity index 100% rename from mini-api-pod.yaml rename to k8s/mini-api-pod.yaml diff --git a/mini-api-svc.yaml b/k8s/mini-api-svc.yaml similarity index 100% rename from mini-api-svc.yaml rename to k8s/mini-api-svc.yaml From ace53775172ef7c695d7363e3b1276d3bb325ef7 Mon Sep 17 00:00:00 2001 From: Chris Nicolaescu Date: Thu, 21 Mar 2024 13:44:08 +0000 Subject: [PATCH 09/11] Added mini-api-iperf --- Dockerfile | 4 +++- k8s/mini-api-iperf-svc.yaml | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 k8s/mini-api-iperf-svc.yaml diff --git a/Dockerfile b/Dockerfile index 79cdca4..47ee575 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,6 @@ WORKDIR /app/src EXPOSE 3001 -CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--port=3001"] \ No newline at end of file +EXPOSE 5201 + +CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--port=3001"] diff --git a/k8s/mini-api-iperf-svc.yaml b/k8s/mini-api-iperf-svc.yaml new file mode 100644 index 0000000..ef2c556 --- /dev/null +++ b/k8s/mini-api-iperf-svc.yaml @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# @Author: Chris Nicolaescu +# @Date: 2024-01-07 +# @Last Modified by: +# @Last Modified time: +apiVersion: v1 +kind: Service +metadata: + name: mini-api-svc +spec: + type: NodePort + ports: + - port: 31201 + targetPort: 5201001 + nodePort: 31201 + protocol: TCP + name: mini-api + selector: + app: mini-api From f00dd1962aa2c8317462f67b1b9a9546086ba507 Mon Sep 17 00:00:00 2001 From: Andrei Radulescu Date: Fri, 22 Mar 2024 19:01:55 +0200 Subject: [PATCH 10/11] fixed targetPort to 5201 --- k8s/mini-api-iperf-svc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/mini-api-iperf-svc.yaml b/k8s/mini-api-iperf-svc.yaml index ef2c556..dd6dbce 100644 --- a/k8s/mini-api-iperf-svc.yaml +++ b/k8s/mini-api-iperf-svc.yaml @@ -11,7 +11,7 @@ spec: type: NodePort ports: - port: 31201 - targetPort: 5201001 + targetPort: 5201 nodePort: 31201 protocol: TCP name: mini-api From f6549fe6186bee17e423e8c8715b2d2d6f2231fb Mon Sep 17 00:00:00 2001 From: Chrisys93 Date: Fri, 22 Mar 2024 20:16:40 +0000 Subject: [PATCH 11/11] Added chart and good nodeport Changed the iperf nodePort to be properly defined and tested it, and added previously-developed MiniAPI helm chart (there might be one on the harbor already, by accident) --- k8s/chart/Chart.yaml | 24 ++++++ k8s/chart/Chart.yaml.save | 24 ++++++ k8s/chart/mini-api-iperf-svc.yaml | 19 +++++ k8s/chart/mini-api-svc.yaml | 19 +++++ k8s/chart/templates/NOTES.txt | 22 +++++ k8s/chart/templates/_helpers.tpl | 62 ++++++++++++++ k8s/chart/templates/deployment.yaml | 67 +++++++++++++++ k8s/chart/templates/hpa.yaml | 28 +++++++ k8s/chart/templates/ingress.yaml | 61 ++++++++++++++ k8s/chart/templates/serviceaccount.yaml | 12 +++ .../templates/tests/test-connection.yaml | 15 ++++ k8s/chart/values.yaml | 81 +++++++++++++++++++ k8s/mini-api-iperf-svc.yaml | 4 +- k8s/mini-api-pod.yaml | 2 +- 14 files changed, 437 insertions(+), 3 deletions(-) create mode 100644 k8s/chart/Chart.yaml create mode 100644 k8s/chart/Chart.yaml.save create mode 100644 k8s/chart/mini-api-iperf-svc.yaml create mode 100644 k8s/chart/mini-api-svc.yaml create mode 100755 k8s/chart/templates/NOTES.txt create mode 100755 k8s/chart/templates/_helpers.tpl create mode 100644 k8s/chart/templates/deployment.yaml create mode 100755 k8s/chart/templates/hpa.yaml create mode 100755 k8s/chart/templates/ingress.yaml create mode 100755 k8s/chart/templates/serviceaccount.yaml create mode 100755 k8s/chart/templates/tests/test-connection.yaml create mode 100644 k8s/chart/values.yaml diff --git a/k8s/chart/Chart.yaml b/k8s/chart/Chart.yaml new file mode 100644 index 0000000..42795d9 --- /dev/null +++ b/k8s/chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: mini-api-helm +description: A Helm chart for Kubernetes mini-api + +# 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.1.0 + +# 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: "1.0" diff --git a/k8s/chart/Chart.yaml.save b/k8s/chart/Chart.yaml.save new file mode 100644 index 0000000..bc7ab4d --- /dev/null +++ b/k8s/chart/Chart.yaml.save @@ -0,0 +1,24 @@ +apiVersion: v2 +name: mini-api +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.1.5 + +# 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: "1.16.0" diff --git a/k8s/chart/mini-api-iperf-svc.yaml b/k8s/chart/mini-api-iperf-svc.yaml new file mode 100644 index 0000000..0f67102 --- /dev/null +++ b/k8s/chart/mini-api-iperf-svc.yaml @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# @Author: Chris Nicolaescu +# @Date: 2024-01-07 +# @Last Modified by: +# @Last Modified time: +apiVersion: v1 +kind: Service +metadata: + name: iperf-svc +spec: + type: NodePort + ports: + - port: 31201 + targetPort: 5201 + nodePort: 31201 + protocol: TCP + name: mini-api + selector: + {{- include "mini-api-helm.selectorLabels" . | nindent 4 }} diff --git a/k8s/chart/mini-api-svc.yaml b/k8s/chart/mini-api-svc.yaml new file mode 100644 index 0000000..5e28b14 --- /dev/null +++ b/k8s/chart/mini-api-svc.yaml @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# @Author: Chris Nicolaescu +# @Date: 2024-01-07 +# @Last Modified by: +# @Last Modified time: +apiVersion: v1 +kind: Service +metadata: + name: mini-api-svc +spec: + type: NodePort + ports: + - port: 31001 + targetPort: 3001 + nodePort: 31001 + protocol: TCP + name: mini-api + selector: + {{- include "mini-api-helm.selectorLabels" . | nindent 4 }} diff --git a/k8s/chart/templates/NOTES.txt b/k8s/chart/templates/NOTES.txt new file mode 100755 index 0000000..3972925 --- /dev/null +++ b/k8s/chart/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 "mini-api-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 the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "mini-api-helm.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "mini-api-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 "mini-api-helm.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 +{{- end }} diff --git a/k8s/chart/templates/_helpers.tpl b/k8s/chart/templates/_helpers.tpl new file mode 100755 index 0000000..54eadf6 --- /dev/null +++ b/k8s/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mini-api-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 "mini-api-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 "mini-api-helm.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mini-api-helm.labels" -}} +helm.sh/chart: {{ include "mini-api-helm.chart" . }} +{{ include "mini-api-helm.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mini-api-helm.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mini-api-helm.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "mini-api-helm.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "mini-api-helm.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/k8s/chart/templates/deployment.yaml b/k8s/chart/templates/deployment.yaml new file mode 100644 index 0000000..af48ef4 --- /dev/null +++ b/k8s/chart/templates/deployment.yaml @@ -0,0 +1,67 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mini-api-helm.fullname" . }} + labels: + {{- include "mini-api-helm.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "mini-api-helm.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "mini-api-helm.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "mini-api-helm.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: mini-api + containerPort: 3001 + protocol: TCP + livenessProbe: + initialDelaySeconds: 30 + timeoutSeconds: 5 + periodSeconds: 30 + httpGet: + path: / + port: mini-api + readinessProbe: + initialDelaySeconds: 30 + timeoutSeconds: 5 + periodSeconds: 30 + httpGet: + path: / + port: mini-api + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- 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/k8s/chart/templates/hpa.yaml b/k8s/chart/templates/hpa.yaml new file mode 100755 index 0000000..05c8856 --- /dev/null +++ b/k8s/chart/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "mini-api-helm.fullname" . }} + labels: + {{- include "mini-api-helm.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "mini-api-helm.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/k8s/chart/templates/ingress.yaml b/k8s/chart/templates/ingress.yaml new file mode 100755 index 0000000..e55eb40 --- /dev/null +++ b/k8s/chart/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "mini-api-helm.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "mini-api-helm.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- 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 }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/k8s/chart/templates/serviceaccount.yaml b/k8s/chart/templates/serviceaccount.yaml new file mode 100755 index 0000000..b1a92f4 --- /dev/null +++ b/k8s/chart/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "mini-api-helm.serviceAccountName" . }} + labels: + {{- include "mini-api-helm.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/k8s/chart/templates/tests/test-connection.yaml b/k8s/chart/templates/tests/test-connection.yaml new file mode 100755 index 0000000..602b9cd --- /dev/null +++ b/k8s/chart/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "mini-api-helm.fullname" . }}-test-connection" + labels: + {{- include "mini-api-helm.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "mini-api-helm.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/k8s/chart/values.yaml b/k8s/chart/values.yaml new file mode 100644 index 0000000..16fa558 --- /dev/null +++ b/k8s/chart/values.yaml @@ -0,0 +1,81 @@ +# Default values for emho-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: harbor.patras5g.eu/5gasp/mini-api-server + pullPolicy: Always + # Overrides the image tag whose default is the chart appVersion. + tag: latest-uob + +serviceAccount: + # Specifies whether a service account should be created + create: 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: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: NodePort + externalPort: 31001 + internalPort: 3001 + nodePort: 30101 + name: mini-api + +ingress: + enabled: false + className: nginx + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + #hosts: + # - host: chart-example.local + # paths: + # - path: / + # 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 + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/k8s/mini-api-iperf-svc.yaml b/k8s/mini-api-iperf-svc.yaml index ef2c556..5af4493 100644 --- a/k8s/mini-api-iperf-svc.yaml +++ b/k8s/mini-api-iperf-svc.yaml @@ -6,12 +6,12 @@ apiVersion: v1 kind: Service metadata: - name: mini-api-svc + name: iperf-svc spec: type: NodePort ports: - port: 31201 - targetPort: 5201001 + targetPort: 5201 nodePort: 31201 protocol: TCP name: mini-api diff --git a/k8s/mini-api-pod.yaml b/k8s/mini-api-pod.yaml index 657f972..61a864d 100644 --- a/k8s/mini-api-pod.yaml +++ b/k8s/mini-api-pod.yaml @@ -12,7 +12,7 @@ metadata: spec: containers: - name: mini-api - image: harbor.patras5g.eu/5gasp/mini-api-server:latest-x86 + image: harbor.patras5g.eu/5gasp/mini-api-server:latest-uob ports: - name: http containerPort: 3001