From 1c1ddfd603fae2774e41984dc77bbbe02963ed25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Alfred=C3=A9en?= Date: Mon, 29 Apr 2024 12:36:14 +0200 Subject: [PATCH] Authentication in UI (#11) --- .gitignore | 3 +++ README.md | 24 +++++++++++++++++++++++- argocd/application.yaml | 16 ++++++++++++++++ manifests/deployment.yaml | 22 ++++++++++++++++++++++ manifests/ingress.yaml | 28 ++++++++++++++++++++++++++++ manifests/namespace.yaml | 4 ++++ manifests/service.yaml | 13 +++++++++++++ 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 argocd/application.yaml create mode 100644 manifests/deployment.yaml create mode 100644 manifests/ingress.yaml create mode 100644 manifests/namespace.yaml create mode 100644 manifests/service.yaml diff --git a/.gitignore b/.gitignore index 90ae6d7..536e017 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,9 @@ dmypy.json # Cython debug symbols cython_debug/ +# Locust deployment +locust-auth + # Locust output files source/reports/* !source/reports/.gitkeep diff --git a/README.md b/README.md index accb6a0..d78f4a6 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,6 @@ $ chmod +x run_test_plan.sh $ ./run_test_plan.sh ``` - ## Use a custom built docker image cd ./source @@ -158,3 +157,26 @@ $ ./run_test_plan.sh docker build -t serve-load-testing . docker run -p 8089:8089 serve-load-testing + +## Deploy to kubernetes + +### Using ArgoCD + +Create a new ArgoCD app using the application manifest ./argocd/application.yaml + +### Using CLI kubectl + +Create a deployment named locust-deployment in a new namespace locust: + + kubectl apply -f ./manifests --force + +### Create a secret for the Locust web UI + +Create a secret named locust-ui-secret. +Required apache2-utils + + sudo apt install apache2-utils + + htpasswd -bc locust-auth locust + + kubectl -n locust create secret generic locust-ui-secret --from-file=locust-auth diff --git a/argocd/application.yaml b/argocd/application.yaml new file mode 100644 index 0000000..d1d4f21 --- /dev/null +++ b/argocd/application.yaml @@ -0,0 +1,16 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: serve-locust +spec: + destination: + namespace: locust + server: 'https://kubernetes.default.svc' + project: default + source: + repoURL: https://github.com/ScilifelabDataCentre/serve-load-testing + path: manifests + targetRevision: develop + syncPolicy: + syncOptions: + - CreateNamespace=true diff --git a/manifests/deployment.yaml b/manifests/deployment.yaml new file mode 100644 index 0000000..dbdc5bd --- /dev/null +++ b/manifests/deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: locust-deployment + namespace: locust +spec: + replicas: 1 + selector: + matchLabels: + app: locust + template: + metadata: + labels: + app: locust + annotations: + statefulset.kubernetes.io/pod-name: locust + spec: + containers: + - name: locust + image: ghcr.io/scilifelabdatacentre/serve-load-testing:main-20240419-1108 + ports: + - containerPort: 8089 diff --git a/manifests/ingress.yaml b/manifests/ingress.yaml new file mode 100644 index 0000000..a75fcf0 --- /dev/null +++ b/manifests/ingress.yaml @@ -0,0 +1,28 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: locust-ingress + namespace: locust + annotations: + kubernetes.io/ingress.class: "nginx" + cert-manager.io/cluster-issuer: "letsencrypt-issuer" + nginx.ingress.kubernetes.io/auth-type: basic + nginx.ingress.kubernetes.io/auth-secret: locust-ui-secret + nginx.ingress.kubernetes.io/auth-realm: "Protected area" +spec: + rules: + - host: locust.serve-dev.scilifelab.se #localhost + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: locust-service + port: + number: 80 #8089 + #ingressClassName: nginx + tls: + - hosts: + - locust.serve-dev.scilifelab.se + secretName: locust-tls diff --git a/manifests/namespace.yaml b/manifests/namespace.yaml new file mode 100644 index 0000000..c523ff4 --- /dev/null +++ b/manifests/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: locust diff --git a/manifests/service.yaml b/manifests/service.yaml new file mode 100644 index 0000000..1319340 --- /dev/null +++ b/manifests/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: locust-service + namespace: locust +spec: + selector: + app: locust + ports: + - protocol: TCP + port: 80 #8089 + targetPort: 8089 + type: ClusterIP #NodePort