diff --git a/.gitignore b/.gitignore index f835063d0c2a1d55f91d0e4c9e873f49253b0d7a..b1587fa8e4cb2eada1cd068ac115e1da0ff9b4f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.bat \ No newline at end of file +.bat +.idea \ No newline at end of file diff --git a/justfile b/justfile index 9d1ff9ba3bcc10d39ab3845e013b7c5662a95483..27d1589a9b408ba015d3bac643a2320bd1301a48 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,6 @@ set windows-shell := ["pwsh", "-c"] -ctxt := "minikube" +ctxt := "c4c" ctxt_flag := "--context " + ctxt default: @@ -8,14 +8,13 @@ default: [no-exit-message] apply a: - kubectl apply {{ ctxt_flag }} -f {{ a }} + kubectl apply {{ ctxt_flag }} -f {{ a }} [no-exit-message] -apply-all: (apply "services.yaml") (apply "config-maps.yaml") (apply "backend-deployment.yaml") (apply "frontend-deployment.yaml") - +apply-all: (apply "old/services.yaml") (apply "old/config-maps.yaml") (apply "old/backend-deployment.yaml") (apply "old/frontend-deployment.yaml") [no-exit-message] -restart-fronted: +restart-frontend: kubectl rollout {{ ctxt_flag }} restart deployment maed-exporter-frontend [no-exit-message] @@ -23,7 +22,7 @@ restart-backend: kubectl rollout {{ ctxt_flag }} restart deployment maed-exporter-backend [no-exit-message] -restart: restart-backend restart-fronted +restart: restart-backend restart-frontend with-label := "true" @@ -34,3 +33,39 @@ do *args="describe deployments": [no-exit-message] minikube-start *args: minikube start --apiserver-port=8888 --namespace mdata {{ args }} + +helm-package: + cd helm/ && helm package superset-mitm-service + +helm-push a: helm-package + # helm registry login registry-1.docker.io -u leahtgu + cd helm/ && helm push {{ a }} oci://registry-1.docker.io/leahtgu + +helm-install: + helm --kube-context c4c -n mdata install maed-exporter-app maed-exporter-app + +helm-install-dry: + helm --kube-context c4c -n mdata install maed-exporter-app maed-exporter-app --dry-run > dryrun.yaml + +helm-uninstall: + helm --kube-context c4c -n mdata uninstall maed-exporter-app + +kube-forward: + #! powershell + $POD_NAME = kubectl --context=c4c get pods --namespace mdata -l "app.kubernetes.io/name=maed-exporter-app,app.kubernetes.io/instance=backend" -o jsonpath="{.items[0].metadata.name}" + $CONTAINER_PORT = kubectl --context=c4c get pod --namespace mdata $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}" + Write-Output "Visit http://127.0.0.1:8080 to use your application" + kubectl --context=c4c --namespace mdata port-forward $POD_NAME 8080:$CONTAINER_PORT + +kube *arg: + kubectl --context=c4c -n mdata {{ arg }} + +kubeinto comp="backend" svc="maed-exporter-app": + #! powershell + $POD_NAME = kubectl --context=c4c get pods --namespace mdata -l "app.kubernetes.io/name={{ svc }},app.kubernetes.io/component={{ comp }}" -o jsonpath="{.items[0].metadata.name}" + kubectl --context=c4c --namespace mdata exec --stdin --tty $POD_NAME -- /bin/bash + +kubelogs comp="backend" svc="maed-exporter-app": + #! powershell + $POD_NAME = kubectl --context=c4c get pods --namespace mdata -l "app.kubernetes.io/name={{ svc }},app.kubernetes.io/component={{ comp }}" -o jsonpath="{.items[0].metadata.name}" + kubectl --context=c4c --namespace mdata logs $POD_NAME diff --git a/maed-exporter-app/.helmignore b/maed-exporter-app/.helmignore new file mode 100644 index 0000000000000000000000000000000000000000..0e8a0eb36f4ca2c939201c0d54b5d82a1ea34778 --- /dev/null +++ b/maed-exporter-app/.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/maed-exporter-app/Chart.yaml b/maed-exporter-app/Chart.yaml new file mode 100644 index 0000000000000000000000000000000000000000..38d7b971aeb9b24e6203032e708abc0c260f4d7d --- /dev/null +++ b/maed-exporter-app/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: maed-exporter-app +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.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: "0.1.0" diff --git a/maed-exporter-app/templates/_helpers.tpl b/maed-exporter-app/templates/_helpers.tpl new file mode 100644 index 0000000000000000000000000000000000000000..8ff3a454b1aca88f8e8e8f93e09b36233454a46f --- /dev/null +++ b/maed-exporter-app/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "maed-exporter-app.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 "maed-exporter-app.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 "maed-exporter-app.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "maed-exporter-app.labels" -}} +helm.sh/chart: {{ include "maed-exporter-app.chart" . }} +{{ include "maed-exporter-app.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "maed-exporter-app.selectorLabels" -}} +app.kubernetes.io/name: {{ include "maed-exporter-app.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "maed-exporter-app.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "maed-exporter-app.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/maed-exporter-app/templates/app-config-map.yaml b/maed-exporter-app/templates/app-config-map.yaml new file mode 100644 index 0000000000000000000000000000000000000000..45196084ae0e1450c4a1a3b7016c85ee947c3353 --- /dev/null +++ b/maed-exporter-app/templates/app-config-map.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: maed-exporter-env + labels: + app.kubernetes.io/name: maed-exporter-app + {{- include "maed-exporter-app.labels" . | nindent 4 }} +data: + FRONTEND_PORT: "{{ .Values.frontend.port | default 8090 }}" + API_BASE: "maed-exporter-backend-svc" + API_PORT: "{{ .Values.backend.port | default 8080 }}" + API_PREFIX: "/api" + EXPORT_DIR: "/exports/" + UPLOAD_DIR: "/uploads/" + CORS_ORIGIN: "maed-exporter-frontend-svc:8090" \ No newline at end of file diff --git a/maed-exporter-app/templates/backend-deployment.yaml b/maed-exporter-app/templates/backend-deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..dc235585a918c88d03c0abf35b52b1fb7901cf61 --- /dev/null +++ b/maed-exporter-app/templates/backend-deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: maed-exporter-backend + {{- if .Values.namespace }} + namespace: {{.Values.namespace | quote }} + {{- end }} + labels: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: backend + app.kubernetes.io/version: {{.Chart.AppVersion }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: backend + replicas: 1 + template: + metadata: + labels: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: backend + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + spec: + containers: + - name: maed-exporter-backend + image: {{.Values.backend.image}} + imagePullPolicy: Always + ports: + - containerPort: {{.Values.backend.port | default 8080 }} + protocol: TCP + envFrom: + - configMapRef: + name: maed-exporter-env + volumeMounts: + - mountPath: /exports + name: exports + - mountPath: /uploads + name: uploads + resources: + limits: + memory: "2Gi" + cpu: "1000m" + requests: + memory: "512Mi" + cpu: "500m" + livenessProbe: + httpGet: + path: /health + port: {{ .Values.backend.port | default 8080}} + initialDelaySeconds: 30 + periodSeconds: 60 + timeoutSeconds: 2 + failureThreshold: 3 + readinessProbe: + httpGet: + path: /health + port: {{ .Values.backend.port | default 8080}} + initialDelaySeconds: 30 + periodSeconds: 60 + timeoutSeconds: 2 + failureThreshold: 3 + volumes: + - name: exports + emptyDir: + sizeLimit: "1Gi" + - name: uploads + emptyDir: + sizeLimit: "1Gi" + + + diff --git a/maed-exporter-app/templates/backend-svc.yaml b/maed-exporter-app/templates/backend-svc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..98e8433407107dafc10b6d609af4d4e237a73841 --- /dev/null +++ b/maed-exporter-app/templates/backend-svc.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: maed-exporter-backend-svc + {{- if .Values.namespace }} + namespace: {{.Values.namespace | quote }} + {{- end }} + labels: + app.kubernetes.io/name: maed-exporter-app + {{- include "maed-exporter-app.labels" . | nindent 4 }} +spec: + selector: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: backend + ports: + - protocol: TCP + port: {{ .Values.backend.port | default 8080 }} + type: ClusterIP \ No newline at end of file diff --git a/maed-exporter-app/templates/frontend-deployment.yaml b/maed-exporter-app/templates/frontend-deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..eb62aeaee94e5a2885c187c93d45b7535927af7c --- /dev/null +++ b/maed-exporter-app/templates/frontend-deployment.yaml @@ -0,0 +1,77 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: maed-exporter-frontend + {{- if .Values.namespace }} + namespace: {{.Values.namespace | quote }} + {{- end }} + labels: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: frontend + app.kubernetes.io/version: {{.Chart.AppVersion }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: frontend + replicas: 1 + revisionHistoryLimit: 5 + strategy: + type: Recreate + template: + metadata: + labels: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: frontend + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + spec: + initContainers: + - name: wait-for-backend + image: curlimages/curl:latest + command: + - sh + - -c + - "until curl -sf http://maed-exporter-backend-svc:{{ .Values.backend.port | default 8080 }}/api/health; do echo 'Waiting for backend...'; sleep 5; done" + containers: + - name: maed-exporter-frontend + image: {{.Values.frontend.image}} + imagePullPolicy: Always + ports: + - containerPort: {{ .Values.frontend.port | default 8090}} + protocol: TCP + envFrom: + - configMapRef: + name: maed-exporter-env + volumeMounts: + - name: nginx-cfg + mountPath: /etc/nginx/templates/default.conf.template #/etc/nginx/conf.d/default.conf + subPath: default.conf.template + resources: + limits: + memory: "1Gi" + cpu: "1000m" + requests: + memory: "1Gi" + cpu: "500m" + livenessProbe: + httpGet: + path: /health + port: {{ .Values.frontend.port | default 8090}} + initialDelaySeconds: 15 + periodSeconds: 60 + timeoutSeconds: 2 + failureThreshold: 3 + readinessProbe: + httpGet: + path: /health + port: {{ .Values.frontend.port | default 8090}} + initialDelaySeconds: 15 + periodSeconds: 60 + timeoutSeconds: 2 + failureThreshold: 3 + volumes: + - name: nginx-cfg + configMap: + name: nginx-cfg diff --git a/maed-exporter-app/templates/frontend-svc.yaml b/maed-exporter-app/templates/frontend-svc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6c67200942da091fb12415dadb5fb624c666618c --- /dev/null +++ b/maed-exporter-app/templates/frontend-svc.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: maed-exporter-frontend-svc + {{- if .Values.namespace }} + namespace: {{.Values.namespace | quote }} + {{- end }} + labels: + app.kubernetes.io/name: maed-exporter-app + {{- include "maed-exporter-app.labels" . | nindent 4 }} +spec: + selector: + app.kubernetes.io/name: maed-exporter-app + app.kubernetes.io/component: frontend + ports: + - protocol: TCP + port: {{ .Values.frontend.port | default 8090 }} \ No newline at end of file diff --git a/maed-exporter-app/templates/nginx-config-map.yaml b/maed-exporter-app/templates/nginx-config-map.yaml new file mode 100644 index 0000000000000000000000000000000000000000..686a25d20980f641976d8b73bcb365a9676c03e9 --- /dev/null +++ b/maed-exporter-app/templates/nginx-config-map.yaml @@ -0,0 +1,43 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: nginx-cfg + labels: + app.kubernetes.io/name: maed-exporter-app + {{- include "maed-exporter-app.labels" . | nindent 4 }} +data: + # hash $cookie_simple_session consistent; + # proxy_set_header X-Real-IP $remote_addr; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # proxy_set_header X-Forwarded-Proto $scheme; + default.conf.template: | + upstream api { + hash $cookie_simple_session consistent; + server ${API_BASE}:${API_PORT} max_fails=3 fail_timeout=30s; + } + + server { + listen ${FRONTEND_PORT}; + + location / { + index index.html; + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html =404; + } + + location /health { + access_log off; + add_header 'Content-Type' 'application/json'; + return 200 '{"status":"healthy"}'; + } + + + location ${API_PREFIX} { + proxy_pass http://api; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_http_version 1.1; + } + } \ No newline at end of file diff --git a/maed-exporter-app/templates/tests/test-connection.yaml b/maed-exporter-app/templates/tests/test-connection.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4a7b0f12a72c31c8c25421682634ded4b0474fa8 --- /dev/null +++ b/maed-exporter-app/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "maed-exporter-app-test-connection" + labels: + {{- include "maed-exporter-app.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: [ 'wget' ] + args: [ 'maed-exporter-backend-svc:{{ .Values.backend.port }}' ] + restartPolicy: Never diff --git a/maed-exporter-app/values.yaml b/maed-exporter-app/values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..79670267bfea61585af261bc2ed8f394be59b164 --- /dev/null +++ b/maed-exporter-app/values.yaml @@ -0,0 +1,9 @@ +namespace: mdata + +backend: + image: registry.git-ce.rwth-aachen.de/machine-data/maed-exporter/maed-exporter-backend:release + port: 8080 + +frontend: + image: registry.git-ce.rwth-aachen.de/machine-data/maed-exporter/maed-exporter-frontend:release + port: 8090 \ No newline at end of file diff --git a/backend-deployment.yaml b/old/backend-deployment.yaml similarity index 100% rename from backend-deployment.yaml rename to old/backend-deployment.yaml diff --git a/config-maps.yaml b/old/config-maps.yaml similarity index 91% rename from config-maps.yaml rename to old/config-maps.yaml index 12cd25e7a93135f52d7179deefe80a795c07775f..5ae003f172ef57d7090abf30066259065cf83abe 100644 --- a/config-maps.yaml +++ b/old/config-maps.yaml @@ -6,12 +6,12 @@ metadata: app.kubernetes.io/name: maed-exporter-app data: FRONTEND_PORT: "8090" - API_BASE: "maed-exporter-backend-svc.mdata.svc.cluster.local" + API_BASE: "maed-exporter-backend-svc" API_PORT: "8080" API_PREFIX: "/api" EXPORT_DIR: "/exports/" UPLOAD_DIR: "/uploads/" - CORS_ORIGIN: "maed-exporter-frontend-svc.mdata.svc.cluster.local:8090" + CORS_ORIGIN: "maed-exporter-frontend-svc:8090" --- apiVersion: v1 kind: ConfigMap diff --git a/frontend-deployment.yaml b/old/frontend-deployment.yaml similarity index 100% rename from frontend-deployment.yaml rename to old/frontend-deployment.yaml diff --git a/services.yaml b/old/services.yaml similarity index 100% rename from services.yaml rename to old/services.yaml