Skip to content
Snippets Groups Projects
Commit 5b3a187c authored by Leah Tacke genannt Unterberg's avatar Leah Tacke genannt Unterberg
Browse files

helmed the kubernetes deployment

parent da0432b3
No related branches found
No related tags found
No related merge requests found
Showing
with 422 additions and 9 deletions
.bat .bat
.idea
\ No newline at end of file
set windows-shell := ["pwsh", "-c"] set windows-shell := ["pwsh", "-c"]
ctxt := "minikube" ctxt := "c4c"
ctxt_flag := "--context " + ctxt ctxt_flag := "--context " + ctxt
default: default:
...@@ -11,11 +11,10 @@ apply a: ...@@ -11,11 +11,10 @@ apply a:
kubectl apply {{ ctxt_flag }} -f {{ a }} kubectl apply {{ ctxt_flag }} -f {{ a }}
[no-exit-message] [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] [no-exit-message]
restart-fronted: restart-frontend:
kubectl rollout {{ ctxt_flag }} restart deployment maed-exporter-frontend kubectl rollout {{ ctxt_flag }} restart deployment maed-exporter-frontend
[no-exit-message] [no-exit-message]
...@@ -23,7 +22,7 @@ restart-backend: ...@@ -23,7 +22,7 @@ restart-backend:
kubectl rollout {{ ctxt_flag }} restart deployment maed-exporter-backend kubectl rollout {{ ctxt_flag }} restart deployment maed-exporter-backend
[no-exit-message] [no-exit-message]
restart: restart-backend restart-fronted restart: restart-backend restart-frontend
with-label := "true" with-label := "true"
...@@ -34,3 +33,39 @@ do *args="describe deployments": ...@@ -34,3 +33,39 @@ do *args="describe deployments":
[no-exit-message] [no-exit-message]
minikube-start *args: minikube-start *args:
minikube start --apiserver-port=8888 --namespace mdata {{ 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
# 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/
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"
{{/*
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 }}
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
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"
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
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
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
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
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
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
File moved
...@@ -6,12 +6,12 @@ metadata: ...@@ -6,12 +6,12 @@ metadata:
app.kubernetes.io/name: maed-exporter-app app.kubernetes.io/name: maed-exporter-app
data: data:
FRONTEND_PORT: "8090" FRONTEND_PORT: "8090"
API_BASE: "maed-exporter-backend-svc.mdata.svc.cluster.local" API_BASE: "maed-exporter-backend-svc"
API_PORT: "8080" API_PORT: "8080"
API_PREFIX: "/api" API_PREFIX: "/api"
EXPORT_DIR: "/exports/" EXPORT_DIR: "/exports/"
UPLOAD_DIR: "/uploads/" UPLOAD_DIR: "/uploads/"
CORS_ORIGIN: "maed-exporter-frontend-svc.mdata.svc.cluster.local:8090" CORS_ORIGIN: "maed-exporter-frontend-svc:8090"
--- ---
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
......
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment