From 97aded5c2f4878f6f20dde682f0bc16d93c2ac6d Mon Sep 17 00:00:00 2001
From: Leah Tacke genannt Unterberg <leah.tgu@pads.rwth-aachen.de>
Date: Thu, 7 Nov 2024 09:29:29 +0100
Subject: [PATCH] fixed nginx proxy misconfiguration

---
 README.md                |  3 +--
 apply-all-c4c.bat        |  1 +
 apply-all.bat            |  2 +-
 backend-deployment.yaml  |  4 ++--
 config-maps.yaml         | 34 +++++-----------------------------
 frontend-deployment.yaml |  8 ++++----
 restart-c4c.bat          |  2 ++
 restart.bat              |  2 ++
 services.yaml            |  3 +--
 9 files changed, 19 insertions(+), 40 deletions(-)
 create mode 100644 apply-all-c4c.bat
 create mode 100644 restart-c4c.bat
 create mode 100644 restart.bat

diff --git a/README.md b/README.md
index eb3c896..fe9f157 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
 # maed-exporter-deployment
 
 This project contains the specification of a kubernetes deployment of the [maed-exporter-app](https://git-ce.rwth-aachen.de/machine-data/maed-exporter/maed-exporter-app).
-
-The environment variable config for the frontend <> backend connection needs to be fixed.
\ No newline at end of file
+It is configured such that the `maed-exporter-frontend-svc` can be exposed to a kubernetes ingress/gateway.
\ No newline at end of file
diff --git a/apply-all-c4c.bat b/apply-all-c4c.bat
new file mode 100644
index 0000000..b669222
--- /dev/null
+++ b/apply-all-c4c.bat
@@ -0,0 +1 @@
+kubectl -n mdata --context=c4c apply -f .\backend-deployment.yaml -f .\frontend-deployment.yaml -f .\config-maps.yaml -f .\services.yaml
\ No newline at end of file
diff --git a/apply-all.bat b/apply-all.bat
index 715c6bf..7b24024 100644
--- a/apply-all.bat
+++ b/apply-all.bat
@@ -1 +1 @@
-kubectl apply -f .\backend-deployment.yaml -f .\frontend-deployment.yaml -f .\config-maps.yaml -f .\services.yaml -n mdata
\ No newline at end of file
+kubectl -n mdata apply -f .\backend-deployment.yaml -f .\frontend-deployment.yaml -f .\config-maps.yaml -f .\services.yaml
\ No newline at end of file
diff --git a/backend-deployment.yaml b/backend-deployment.yaml
index 5a28930..0a2aee2 100644
--- a/backend-deployment.yaml
+++ b/backend-deployment.yaml
@@ -44,7 +44,7 @@ spec:
               path: /health
               port: 8080
             initialDelaySeconds: 30
-            periodSeconds: 15
+            periodSeconds: 60
             timeoutSeconds: 2
             failureThreshold: 3
           readinessProbe:
@@ -52,7 +52,7 @@ spec:
               path: /health
               port: 8080
             initialDelaySeconds: 30
-            periodSeconds: 10
+            periodSeconds: 60
             timeoutSeconds: 2
             failureThreshold: 3
       volumes:
diff --git a/config-maps.yaml b/config-maps.yaml
index 74432b2..a16c13f 100644
--- a/config-maps.yaml
+++ b/config-maps.yaml
@@ -20,6 +20,9 @@ metadata:
     app.kubernetes.io/name: maed-exporter-app
 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;
@@ -47,34 +50,7 @@ data:
           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;
       }
     }
-  default.conf: |
-    upstream api {
-      hash $cookie_simple_session consistent;
-      server maed-exporter-backend-svc.mdata.svc.cluster.local:8080 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 {
-          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;
-      }
-    }
\ No newline at end of file
+    
\ No newline at end of file
diff --git a/frontend-deployment.yaml b/frontend-deployment.yaml
index 3ffa443..102ffd0 100644
--- a/frontend-deployment.yaml
+++ b/frontend-deployment.yaml
@@ -47,16 +47,16 @@ spec:
             httpGet:
               path: /health
               port: 8090
-            initialDelaySeconds: 10
-            periodSeconds: 15
+            initialDelaySeconds: 15
+            periodSeconds: 60
             timeoutSeconds: 2
             failureThreshold: 3
           readinessProbe:
             httpGet:
               path: /health
               port: 8090
-            initialDelaySeconds: 5
-            periodSeconds: 10
+            initialDelaySeconds: 15
+            periodSeconds: 60
             timeoutSeconds: 2
             failureThreshold: 3
       volumes:
diff --git a/restart-c4c.bat b/restart-c4c.bat
new file mode 100644
index 0000000..8211b60
--- /dev/null
+++ b/restart-c4c.bat
@@ -0,0 +1,2 @@
+kubectl -n mdata --context=c4c rollout restart deployment maed-exporter-backend
+kubectl -n mdata --context=c4c rollout restart deployment maed-exporter-frontend
\ No newline at end of file
diff --git a/restart.bat b/restart.bat
new file mode 100644
index 0000000..741d24c
--- /dev/null
+++ b/restart.bat
@@ -0,0 +1,2 @@
+kubectl -n mdata rollout restart deployment maed-exporter-backend
+kubectl -n mdata rollout restart deployment maed-exporter-frontend
\ No newline at end of file
diff --git a/services.yaml b/services.yaml
index 1c78642..ef30527 100644
--- a/services.yaml
+++ b/services.yaml
@@ -29,5 +29,4 @@ spec:
   ports:
     - protocol: TCP
       port: 8090
-      targetPort: 8090
-  type: NodePort
\ No newline at end of file
+      targetPort: 8090
\ No newline at end of file
-- 
GitLab