From 75a28c1819a4d14c7a3ffade5e164b441e44b36c Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Fri, 20 Dec 2024 13:55:04 +0100
Subject: Add networking and balancing

---
 yaml/networking/balance.yaml | 37 +++++++++++++++++++++++++++++++++++++
 yaml/networking/ingress.yaml | 18 ++++++++++++++++++
 yaml/services/cas.yaml       |  2 +-
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 yaml/networking/balance.yaml
 create mode 100644 yaml/networking/ingress.yaml

(limited to 'yaml')

diff --git a/yaml/networking/balance.yaml b/yaml/networking/balance.yaml
new file mode 100644
index 0000000..dd0f17b
--- /dev/null
+++ b/yaml/networking/balance.yaml
@@ -0,0 +1,37 @@
+apiVersion: autoscaling/v2
+kind: HorizontalPodAutoscaler
+metadata:
+  name: cas-hpa
+spec:
+  scaleTargetRef:
+    apiVersion: apps/v1
+    kind: Deployment
+    name: cas-deployment
+  minReplicas: 1
+  maxReplicas: 10
+  metrics:
+  - type: Resource
+    resource:
+      name: cpu
+      target:
+        type: Utilization
+        averageUtilization: 70
+  - type: Resource
+    resource:
+      name: memory
+      target:
+        type: Utilization
+        averageUtilization: 80
+  behavior:
+    scaleUp:
+      stabilizationWindowSeconds: 60
+      policies:
+      - type: Percent
+        value: 100
+        periodSeconds: 15
+    scaleDown:
+      stabilizationWindowSeconds: 300
+      policies:
+      - type: Percent
+        value: 100
+        periodSeconds: 15
diff --git a/yaml/networking/ingress.yaml b/yaml/networking/ingress.yaml
new file mode 100644
index 0000000..4a0d31d
--- /dev/null
+++ b/yaml/networking/ingress.yaml
@@ -0,0 +1,18 @@
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: cas-ingress
+  annotations:
+    nginx.ingress.kubernetes.io/rewrite-target: /
+spec:
+  ingressClassName: nginx
+  rules:
+  - http:
+      paths:
+      - path: /
+        pathType: Prefix
+        backend:
+          service:
+            name: cas-service
+            port:
+              number: 80
diff --git a/yaml/services/cas.yaml b/yaml/services/cas.yaml
index ff1d8c5..bd30fe9 100644
--- a/yaml/services/cas.yaml
+++ b/yaml/services/cas.yaml
@@ -10,4 +10,4 @@ spec:
       protocol: TCP
   selector:
     app: cas
-  type: ClusterIP
+  type: LoadBalancer
-- 
cgit v1.2.3-18-g5258