From 658d150fd6c28edd6c5ebd54b61ee10c8210f149 Mon Sep 17 00:00:00 2001 From: manuelfdg Date: Wed, 16 Apr 2025 00:27:19 +0000 Subject: [PATCH 1/7] add hpa/resources requests and limits --- code/kubernetes/grpc-gateway/deployment.yaml | 7 +++++++ code/kubernetes/hpa/comment-service-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/hpa/community-service-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/hpa/grpc-gateway-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/hpa/popular-service-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/hpa/search-service-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/hpa/thread-service-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/hpa/vote-service-hpa.yaml | 18 ++++++++++++++++++ code/kubernetes/mongo/deployment.yaml | 7 +++++++ code/kubernetes/scripts/deploy.sh | 5 ++++- .../services/comment-service/deployment.yaml | 7 +++++++ .../services/community-service/deployment.yaml | 7 +++++++ .../services/db-service/deployment.yaml | 7 +++++++ .../services/popular-service/deployment.yaml | 7 +++++++ .../services/search-service/deployment.yaml | 7 +++++++ .../services/thread-service/deployment.yaml | 7 +++++++ .../services/vote-service/deployment.yaml | 7 +++++++ 17 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 code/kubernetes/hpa/comment-service-hpa.yaml create mode 100644 code/kubernetes/hpa/community-service-hpa.yaml create mode 100644 code/kubernetes/hpa/grpc-gateway-hpa.yaml create mode 100644 code/kubernetes/hpa/popular-service-hpa.yaml create mode 100644 code/kubernetes/hpa/search-service-hpa.yaml create mode 100644 code/kubernetes/hpa/thread-service-hpa.yaml create mode 100644 code/kubernetes/hpa/vote-service-hpa.yaml diff --git a/code/kubernetes/grpc-gateway/deployment.yaml b/code/kubernetes/grpc-gateway/deployment.yaml index 75515f1..02885f1 100644 --- a/code/kubernetes/grpc-gateway/deployment.yaml +++ b/code/kubernetes/grpc-gateway/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 8080 + resources: + requests: + cpu: "200m" + memory: "256Mi" + limits: + cpu: "500m" + memory: "512Mi" env: - name: GRPC_GATEWAY_PORT valueFrom: diff --git a/code/kubernetes/hpa/comment-service-hpa.yaml b/code/kubernetes/hpa/comment-service-hpa.yaml new file mode 100644 index 0000000..8826295 --- /dev/null +++ b/code/kubernetes/hpa/comment-service-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: comment-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: comment-service + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/community-service-hpa.yaml b/code/kubernetes/hpa/community-service-hpa.yaml new file mode 100644 index 0000000..22aca1d --- /dev/null +++ b/code/kubernetes/hpa/community-service-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: community-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: community-service + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/grpc-gateway-hpa.yaml b/code/kubernetes/hpa/grpc-gateway-hpa.yaml new file mode 100644 index 0000000..483318e --- /dev/null +++ b/code/kubernetes/hpa/grpc-gateway-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: grpc-gateway-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: grpc-gateway + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/popular-service-hpa.yaml b/code/kubernetes/hpa/popular-service-hpa.yaml new file mode 100644 index 0000000..b08321b --- /dev/null +++ b/code/kubernetes/hpa/popular-service-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: popular-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: popular-service + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/search-service-hpa.yaml b/code/kubernetes/hpa/search-service-hpa.yaml new file mode 100644 index 0000000..adfb5d1 --- /dev/null +++ b/code/kubernetes/hpa/search-service-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: search-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: search-service + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/thread-service-hpa.yaml b/code/kubernetes/hpa/thread-service-hpa.yaml new file mode 100644 index 0000000..333d0c2 --- /dev/null +++ b/code/kubernetes/hpa/thread-service-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: thread-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: thread-service + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/vote-service-hpa.yaml b/code/kubernetes/hpa/vote-service-hpa.yaml new file mode 100644 index 0000000..f273f07 --- /dev/null +++ b/code/kubernetes/hpa/vote-service-hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: vote-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: vote-service + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/mongo/deployment.yaml b/code/kubernetes/mongo/deployment.yaml index 6f788ff..e3e1739 100644 --- a/code/kubernetes/mongo/deployment.yaml +++ b/code/kubernetes/mongo/deployment.yaml @@ -17,6 +17,13 @@ spec: image: mongo:latest ports: - containerPort: 27017 + resources: + requests: + cpu: "300m" + memory: "512Mi" + limits: + cpu: "700m" + memory: "1Gi" env: - name: MONGO_INITDB_DATABASE valueFrom: diff --git a/code/kubernetes/scripts/deploy.sh b/code/kubernetes/scripts/deploy.sh index d8117c1..2772453 100644 --- a/code/kubernetes/scripts/deploy.sh +++ b/code/kubernetes/scripts/deploy.sh @@ -59,4 +59,7 @@ for SERVICE in "${SERVICES[@]}"; do done # gRPC Gateway -kubectl apply -n $CLUSTER_NAME -f grpc-gateway/ \ No newline at end of file +kubectl apply -n $CLUSTER_NAME -f grpc-gateway/ + +# Apply Horizontal Pod Autoscalers (HPA) +kubectl apply -n $CLUSTER_NAME -f hpa/ diff --git a/code/kubernetes/services/comment-service/deployment.yaml b/code/kubernetes/services/comment-service/deployment.yaml index 22f4dc4..401114c 100644 --- a/code/kubernetes/services/comment-service/deployment.yaml +++ b/code/kubernetes/services/comment-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50054 + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "300m" + memory: "384Mi" env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/community-service/deployment.yaml b/code/kubernetes/services/community-service/deployment.yaml index b9817eb..4632260 100644 --- a/code/kubernetes/services/community-service/deployment.yaml +++ b/code/kubernetes/services/community-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50052 + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "300m" + memory: "384Mi" env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/db-service/deployment.yaml b/code/kubernetes/services/db-service/deployment.yaml index 2b5038e..d84f64f 100644 --- a/code/kubernetes/services/db-service/deployment.yaml +++ b/code/kubernetes/services/db-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50051 + resources: + requests: + cpu: "200m" + memory: "256Mi" + limits: + cpu: "500m" + memory: "512Mi" env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/popular-service/deployment.yaml b/code/kubernetes/services/popular-service/deployment.yaml index 32ee19f..00d86c7 100644 --- a/code/kubernetes/services/popular-service/deployment.yaml +++ b/code/kubernetes/services/popular-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50057 + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "300m" + memory: "384Mi" env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/search-service/deployment.yaml b/code/kubernetes/services/search-service/deployment.yaml index 32b5aaf..3ab83a5 100644 --- a/code/kubernetes/services/search-service/deployment.yaml +++ b/code/kubernetes/services/search-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50056 + resources: + requests: + cpu: "150m" + memory: "192Mi" + limits: + cpu: "400m" + memory: "448Mi" env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/thread-service/deployment.yaml b/code/kubernetes/services/thread-service/deployment.yaml index 86800ac..ca4b053 100644 --- a/code/kubernetes/services/thread-service/deployment.yaml +++ b/code/kubernetes/services/thread-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50053 + resources: + requests: + cpu: "150m" + memory: "192Mi" + limits: + cpu: "400m" + memory: "448Mi" env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/vote-service/deployment.yaml b/code/kubernetes/services/vote-service/deployment.yaml index 8480665..d77fd82 100644 --- a/code/kubernetes/services/vote-service/deployment.yaml +++ b/code/kubernetes/services/vote-service/deployment.yaml @@ -18,6 +18,13 @@ spec: imagePullPolicy: Always ports: - containerPort: 50055 + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "250m" + memory: "256Mi" env: - name: SERVICE_PORT valueFrom: From 2f4a8354abf3d80f4faedf9b5e3c7ee9fc979648 Mon Sep 17 00:00:00 2001 From: manuelfdg Date: Wed, 16 Apr 2025 01:58:10 +0000 Subject: [PATCH 2/7] ... --- code/kubernetes/scripts/cluster-info.sh | 26 +++++++++++++++++++++++++ code/kubernetes/scripts/deploy.sh | 1 + 2 files changed, 27 insertions(+) diff --git a/code/kubernetes/scripts/cluster-info.sh b/code/kubernetes/scripts/cluster-info.sh index 20723d5..6301967 100644 --- a/code/kubernetes/scripts/cluster-info.sh +++ b/code/kubernetes/scripts/cluster-info.sh @@ -11,6 +11,9 @@ SHOW_SERVICES=false SHOW_DEPLOYMENTS=false SHOW_RESOURCES_PODS=false SHOW_RESOURCES_NODES=false +SHOW_HPA=false +SHOW_DETAILED_RESOURCES=false +SHOW_EVENTS=false if [[ $# -eq 0 ]]; then SHOW_NAMESPACES=true @@ -19,6 +22,9 @@ if [[ $# -eq 0 ]]; then SHOW_DEPLOYMENTS=true SHOW_RESOURCES_PODS=true SHOW_RESOURCES_NODES=true + SHOW_HPA=true + SHOW_DETAILED_RESOURCES=true + SHOW_EVENTS=true fi # Parse flags @@ -30,6 +36,9 @@ while [[ "$#" -gt 0 ]]; do --deployments) SHOW_DEPLOYMENTS=true ;; --resources-pods) SHOW_RESOURCES_PODS=true ;; --resources-nodes) SHOW_RESOURCES_NODES=true ;; + --hpa) SHOW_HPA=true ;; + --detailed-resources) SHOW_DETAILED_RESOURCES=true ;; + --events) SHOW_EVENTS=true ;; --all) SHOW_NAMESPACES=true SHOW_PODS=true @@ -37,6 +46,9 @@ while [[ "$#" -gt 0 ]]; do SHOW_DEPLOYMENTS=true SHOW_RESOURCES_PODS=true SHOW_RESOURCES_NODES=true + SHOW_HPA=true + SHOW_DETAILED_RESOURCES=true + SHOW_EVENTS=true ;; *) echo "āŒ Unknown flag: $1"; exit 1 ;; esac @@ -53,3 +65,17 @@ $SHOW_SERVICES && echo -e "\nšŸ” Services:" && kubectl get svc -n $CLUSTER_NAME $SHOW_DEPLOYMENTS && echo -e "\nšŸ“‚ Deployments:" && kubectl get deployments -n $CLUSTER_NAME $SHOW_RESOURCES_PODS && echo -e "\nšŸ“Š Resource Usage (Pods):" && kubectl top pods -n $CLUSTER_NAME $SHOW_RESOURCES_NODES && echo -e "\nšŸ–„ļø Resource Usage (Nodes):" && kubectl top nodes + +# New sections for monitoring HPAs and resource limits +$SHOW_HPA && echo -e "\nāš–ļø Horizontal Pod Autoscalers:" && kubectl get hpa -n $CLUSTER_NAME + +if $SHOW_DETAILED_RESOURCES; then + echo -e "\nšŸ”Ž Detailed Resource Limits and Requests:" + echo "-------------------------------------------" + for pod in $(kubectl get pods -n $CLUSTER_NAME -o=name); do + echo -e "\nšŸ“Œ $pod" + kubectl describe $pod -n $CLUSTER_NAME | grep -A8 "Limits:" | grep -v "Node:" + done +fi + +$SHOW_EVENTS && echo -e "\nšŸ“œ Recent Events (including scaling):" && kubectl get events -n $CLUSTER_NAME --sort-by='.lastTimestamp' | grep -E '(HorizontalPodAutoscaler|scale|Scaled)' \ No newline at end of file diff --git a/code/kubernetes/scripts/deploy.sh b/code/kubernetes/scripts/deploy.sh index 2772453..f4ae4a2 100644 --- a/code/kubernetes/scripts/deploy.sh +++ b/code/kubernetes/scripts/deploy.sh @@ -46,6 +46,7 @@ gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE kubectl apply -n $CLUSTER_NAME -f config.yaml # Traefik +helm repo add traefik https://traefik.github.io/charts helm upgrade --install traefik traefik/traefik -n $CLUSTER_NAME -f traefik/values.yaml kubectl apply -n $CLUSTER_NAME -f traefik/cors.yaml kubectl apply -n $CLUSTER_NAME -f traefik/strip-prefix.yaml From 60b9937ec63e4966b44161069cf37ef0b4f19c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Proen=C3=A7a?= Date: Tue, 20 May 2025 06:06:59 +0100 Subject: [PATCH 3/7] Updated resources requests and limits --- code/kubernetes/mongo/deployment.yaml | 8 ++--- .../services/comment-service/deployment.yaml | 8 ++--- .../community-service/deployment.yaml | 8 ++--- .../services/db-service/deployment.yaml | 8 ++--- .../services/popular-service/deployment.yaml | 8 ++--- .../services/search-service/deployment.yaml | 8 ++--- .../services/thread-service/deployment.yaml | 8 ++--- .../services/vote-service/deployment.yaml | 8 ++--- code/kubernetes/traefik/values.yaml | 33 ++++++++++++------- 9 files changed, 54 insertions(+), 43 deletions(-) diff --git a/code/kubernetes/mongo/deployment.yaml b/code/kubernetes/mongo/deployment.yaml index 06c4fae..a68ce41 100644 --- a/code/kubernetes/mongo/deployment.yaml +++ b/code/kubernetes/mongo/deployment.yaml @@ -19,11 +19,11 @@ spec: - containerPort: 27017 resources: requests: - cpu: "300m" - memory: "512Mi" + cpu: 150m + memory: 700Mi limits: - cpu: "700m" - memory: "1Gi" + cpu: 500m + memory: 1Gi env: - name: MONGO_INITDB_DATABASE valueFrom: diff --git a/code/kubernetes/services/comment-service/deployment.yaml b/code/kubernetes/services/comment-service/deployment.yaml index 8256ced..7d057f7 100644 --- a/code/kubernetes/services/comment-service/deployment.yaml +++ b/code/kubernetes/services/comment-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50054 resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "300m" - memory: "384Mi" + cpu: 50m + memory: 100Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/community-service/deployment.yaml b/code/kubernetes/services/community-service/deployment.yaml index 5b96274..5e42b86 100644 --- a/code/kubernetes/services/community-service/deployment.yaml +++ b/code/kubernetes/services/community-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50052 resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "300m" - memory: "384Mi" + cpu: 50m + memory: 100Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/db-service/deployment.yaml b/code/kubernetes/services/db-service/deployment.yaml index fae6b6e..12621a9 100644 --- a/code/kubernetes/services/db-service/deployment.yaml +++ b/code/kubernetes/services/db-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50051 resources: requests: - cpu: "200m" - memory: "256Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "500m" - memory: "512Mi" + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/popular-service/deployment.yaml b/code/kubernetes/services/popular-service/deployment.yaml index 05e4c41..257a2e2 100644 --- a/code/kubernetes/services/popular-service/deployment.yaml +++ b/code/kubernetes/services/popular-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50057 resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "300m" - memory: "384Mi" + cpu: 50m + memory: 100Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/search-service/deployment.yaml b/code/kubernetes/services/search-service/deployment.yaml index dc4b7d5..a98cd31 100644 --- a/code/kubernetes/services/search-service/deployment.yaml +++ b/code/kubernetes/services/search-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50056 resources: requests: - cpu: "150m" - memory: "192Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "400m" - memory: "448Mi" + cpu: 50m + memory: 100Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/thread-service/deployment.yaml b/code/kubernetes/services/thread-service/deployment.yaml index e115b0c..6eadf1c 100644 --- a/code/kubernetes/services/thread-service/deployment.yaml +++ b/code/kubernetes/services/thread-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50053 resources: requests: - cpu: "150m" - memory: "192Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "400m" - memory: "448Mi" + cpu: 50m + memory: 100Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/vote-service/deployment.yaml b/code/kubernetes/services/vote-service/deployment.yaml index 6343aa8..0ea3a85 100644 --- a/code/kubernetes/services/vote-service/deployment.yaml +++ b/code/kubernetes/services/vote-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50055 resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: 10m + memory: 20Mi limits: - cpu: "250m" - memory: "256Mi" + cpu: 50m + memory: 100Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/traefik/values.yaml b/code/kubernetes/traefik/values.yaml index 9f28b52..504a34c 100644 --- a/code/kubernetes/traefik/values.yaml +++ b/code/kubernetes/traefik/values.yaml @@ -1,12 +1,23 @@ -# https://github.com/traefik/traefik-helm-chart/blob/master/traefik/VALUES.md +# traefik/values.yaml -# autoscaling: # TODO: If needed, uncomment and configure HPA settings -# enabled: true -# maxReplicas: 2 -# metrics: -# - type: Resource -# resource: -# name: cpu -# target: -# type: Utilization -# averageUtilization: 60 +replicaCount: 1 + +resources: + requests: + cpu: 20m + memory: 40Mi + limits: + cpu: 100m + memory: 100Mi + +# TODO: If needed, uncomment and configure HPA settings +#autoscaling: +# enabled: true +# maxReplicas: 2 +# metrics: +# - type: Resource +# resource: +# name: cpu +# target: +# type: Utilization +# averageUtilization: 60 \ No newline at end of file From 3319349b0fd9170aa5668ad8f825bc8822fbfb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Proen=C3=A7a?= Date: Tue, 20 May 2025 06:35:05 +0100 Subject: [PATCH 4/7] Updated hpa configuration --- code/kubernetes/grpc-gateway/deployment.yaml | 19 +++++++++++++++++++ code/kubernetes/hpa/comment-service-hpa.yaml | 18 ------------------ .../kubernetes/hpa/community-service-hpa.yaml | 18 ------------------ code/kubernetes/hpa/grpc-gateway-hpa.yaml | 18 ------------------ code/kubernetes/hpa/popular-service-hpa.yaml | 18 ------------------ code/kubernetes/hpa/search-service-hpa.yaml | 18 ------------------ code/kubernetes/hpa/thread-service-hpa.yaml | 18 ------------------ code/kubernetes/hpa/vote-service-hpa.yaml | 18 ------------------ .../services/comment-service/deployment.yaml | 19 +++++++++++++++++++ .../community-service/deployment.yaml | 19 +++++++++++++++++++ .../services/db-service/deployment.yaml | 19 +++++++++++++++++++ .../services/popular-service/deployment.yaml | 19 +++++++++++++++++++ .../services/search-service/deployment.yaml | 19 +++++++++++++++++++ .../services/thread-service/deployment.yaml | 19 +++++++++++++++++++ .../services/vote-service/deployment.yaml | 19 +++++++++++++++++++ 15 files changed, 152 insertions(+), 126 deletions(-) delete mode 100644 code/kubernetes/hpa/comment-service-hpa.yaml delete mode 100644 code/kubernetes/hpa/community-service-hpa.yaml delete mode 100644 code/kubernetes/hpa/grpc-gateway-hpa.yaml delete mode 100644 code/kubernetes/hpa/popular-service-hpa.yaml delete mode 100644 code/kubernetes/hpa/search-service-hpa.yaml delete mode 100644 code/kubernetes/hpa/thread-service-hpa.yaml delete mode 100644 code/kubernetes/hpa/vote-service-hpa.yaml diff --git a/code/kubernetes/grpc-gateway/deployment.yaml b/code/kubernetes/grpc-gateway/deployment.yaml index 2fa4494..57381f5 100644 --- a/code/kubernetes/grpc-gateway/deployment.yaml +++ b/code/kubernetes/grpc-gateway/deployment.yaml @@ -85,3 +85,22 @@ spec: port: 8080 initialDelaySeconds: 10 timeoutSeconds: 5 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: grpc-gateway-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: grpc-gateway + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/hpa/comment-service-hpa.yaml b/code/kubernetes/hpa/comment-service-hpa.yaml deleted file mode 100644 index 8826295..0000000 --- a/code/kubernetes/hpa/comment-service-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: comment-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: comment-service - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/community-service-hpa.yaml b/code/kubernetes/hpa/community-service-hpa.yaml deleted file mode 100644 index 22aca1d..0000000 --- a/code/kubernetes/hpa/community-service-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: community-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: community-service - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/grpc-gateway-hpa.yaml b/code/kubernetes/hpa/grpc-gateway-hpa.yaml deleted file mode 100644 index 483318e..0000000 --- a/code/kubernetes/hpa/grpc-gateway-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: grpc-gateway-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: grpc-gateway - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/popular-service-hpa.yaml b/code/kubernetes/hpa/popular-service-hpa.yaml deleted file mode 100644 index b08321b..0000000 --- a/code/kubernetes/hpa/popular-service-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: popular-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: popular-service - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/search-service-hpa.yaml b/code/kubernetes/hpa/search-service-hpa.yaml deleted file mode 100644 index adfb5d1..0000000 --- a/code/kubernetes/hpa/search-service-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: search-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: search-service - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/thread-service-hpa.yaml b/code/kubernetes/hpa/thread-service-hpa.yaml deleted file mode 100644 index 333d0c2..0000000 --- a/code/kubernetes/hpa/thread-service-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: thread-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: thread-service - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/hpa/vote-service-hpa.yaml b/code/kubernetes/hpa/vote-service-hpa.yaml deleted file mode 100644 index f273f07..0000000 --- a/code/kubernetes/hpa/vote-service-hpa.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: vote-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: vote-service - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 70 \ No newline at end of file diff --git a/code/kubernetes/services/comment-service/deployment.yaml b/code/kubernetes/services/comment-service/deployment.yaml index 7d057f7..26d5748 100644 --- a/code/kubernetes/services/comment-service/deployment.yaml +++ b/code/kubernetes/services/comment-service/deployment.yaml @@ -55,3 +55,22 @@ spec: port: 50054 initialDelaySeconds: 6 timeoutSeconds: 4 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: comment-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: comment-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/services/community-service/deployment.yaml b/code/kubernetes/services/community-service/deployment.yaml index 5e42b86..71219ef 100644 --- a/code/kubernetes/services/community-service/deployment.yaml +++ b/code/kubernetes/services/community-service/deployment.yaml @@ -55,3 +55,22 @@ spec: port: 50052 initialDelaySeconds: 6 timeoutSeconds: 4 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: community-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: community-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/services/db-service/deployment.yaml b/code/kubernetes/services/db-service/deployment.yaml index 12621a9..9010829 100644 --- a/code/kubernetes/services/db-service/deployment.yaml +++ b/code/kubernetes/services/db-service/deployment.yaml @@ -59,3 +59,22 @@ spec: items: - key: gcs-key.json path: gcs-key.json +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: db-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: db-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/services/popular-service/deployment.yaml b/code/kubernetes/services/popular-service/deployment.yaml index 257a2e2..a9c219d 100644 --- a/code/kubernetes/services/popular-service/deployment.yaml +++ b/code/kubernetes/services/popular-service/deployment.yaml @@ -55,3 +55,22 @@ spec: port: 50057 initialDelaySeconds: 6 timeoutSeconds: 4 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: popular-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: popular-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/services/search-service/deployment.yaml b/code/kubernetes/services/search-service/deployment.yaml index a98cd31..d3e9c07 100644 --- a/code/kubernetes/services/search-service/deployment.yaml +++ b/code/kubernetes/services/search-service/deployment.yaml @@ -55,3 +55,22 @@ spec: port: 50056 initialDelaySeconds: 6 timeoutSeconds: 4 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: search-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: search-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/services/thread-service/deployment.yaml b/code/kubernetes/services/thread-service/deployment.yaml index 6eadf1c..a3c1bd9 100644 --- a/code/kubernetes/services/thread-service/deployment.yaml +++ b/code/kubernetes/services/thread-service/deployment.yaml @@ -55,3 +55,22 @@ spec: port: 50053 initialDelaySeconds: 6 timeoutSeconds: 4 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: thread-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: thread-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file diff --git a/code/kubernetes/services/vote-service/deployment.yaml b/code/kubernetes/services/vote-service/deployment.yaml index 0ea3a85..f5701ee 100644 --- a/code/kubernetes/services/vote-service/deployment.yaml +++ b/code/kubernetes/services/vote-service/deployment.yaml @@ -55,3 +55,22 @@ spec: port: 50055 initialDelaySeconds: 6 timeoutSeconds: 4 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: vote-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: vote-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 \ No newline at end of file From 78e399fbfc77fdde9cdcb3b8a146d003f9f047c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Proen=C3=A7a?= Date: Tue, 20 May 2025 07:39:10 +0100 Subject: [PATCH 5/7] Increased resources values --- code/kubernetes/grpc-gateway/deployment.yaml | 8 ++++---- code/kubernetes/services/comment-service/deployment.yaml | 8 ++++---- .../kubernetes/services/community-service/deployment.yaml | 8 ++++---- code/kubernetes/services/db-service/deployment.yaml | 8 ++++---- code/kubernetes/services/popular-service/deployment.yaml | 8 ++++---- code/kubernetes/services/search-service/deployment.yaml | 8 ++++---- code/kubernetes/services/thread-service/deployment.yaml | 8 ++++---- code/kubernetes/services/vote-service/deployment.yaml | 8 ++++---- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/code/kubernetes/grpc-gateway/deployment.yaml b/code/kubernetes/grpc-gateway/deployment.yaml index 57381f5..5cb8167 100644 --- a/code/kubernetes/grpc-gateway/deployment.yaml +++ b/code/kubernetes/grpc-gateway/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 8080 resources: requests: - cpu: "200m" - memory: "256Mi" + cpu: 30m + memory: 60Mi limits: - cpu: "500m" - memory: "512Mi" + cpu: 120m + memory: 240Mi env: - name: GRPC_GATEWAY_PORT valueFrom: diff --git a/code/kubernetes/services/comment-service/deployment.yaml b/code/kubernetes/services/comment-service/deployment.yaml index 26d5748..691a5a8 100644 --- a/code/kubernetes/services/comment-service/deployment.yaml +++ b/code/kubernetes/services/comment-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50054 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 20m + memory: 40Mi limits: - cpu: 50m - memory: 100Mi + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/community-service/deployment.yaml b/code/kubernetes/services/community-service/deployment.yaml index 71219ef..d0cc0a6 100644 --- a/code/kubernetes/services/community-service/deployment.yaml +++ b/code/kubernetes/services/community-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50052 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 20m + memory: 40Mi limits: - cpu: 50m - memory: 100Mi + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/db-service/deployment.yaml b/code/kubernetes/services/db-service/deployment.yaml index 9010829..5c35074 100644 --- a/code/kubernetes/services/db-service/deployment.yaml +++ b/code/kubernetes/services/db-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50051 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 30m + memory: 60Mi limits: - cpu: 100m - memory: 200Mi + cpu: 120m + memory: 240Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/popular-service/deployment.yaml b/code/kubernetes/services/popular-service/deployment.yaml index a9c219d..adb7d9e 100644 --- a/code/kubernetes/services/popular-service/deployment.yaml +++ b/code/kubernetes/services/popular-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50057 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 20m + memory: 40Mi limits: - cpu: 50m - memory: 100Mi + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/search-service/deployment.yaml b/code/kubernetes/services/search-service/deployment.yaml index d3e9c07..1ac1d49 100644 --- a/code/kubernetes/services/search-service/deployment.yaml +++ b/code/kubernetes/services/search-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50056 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 20m + memory: 40Mi limits: - cpu: 50m - memory: 100Mi + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/thread-service/deployment.yaml b/code/kubernetes/services/thread-service/deployment.yaml index a3c1bd9..86fcbd9 100644 --- a/code/kubernetes/services/thread-service/deployment.yaml +++ b/code/kubernetes/services/thread-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50053 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 20m + memory: 40Mi limits: - cpu: 50m - memory: 100Mi + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: diff --git a/code/kubernetes/services/vote-service/deployment.yaml b/code/kubernetes/services/vote-service/deployment.yaml index f5701ee..97325cd 100644 --- a/code/kubernetes/services/vote-service/deployment.yaml +++ b/code/kubernetes/services/vote-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50055 resources: requests: - cpu: 10m - memory: 20Mi + cpu: 20m + memory: 40Mi limits: - cpu: 50m - memory: 100Mi + cpu: 100m + memory: 200Mi env: - name: SERVICE_PORT valueFrom: From 816fb374b669ee0fa69579a95617ab2525fc4553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Proen=C3=A7a?= Date: Wed, 21 May 2025 01:55:16 +0100 Subject: [PATCH 6/7] Some value changes --- code/kubernetes/grpc-gateway/deployment.yaml | 2 +- code/kubernetes/scripts/create-cluster.sh | 4 +- .../services/comment-service/deployment.yaml | 2 +- .../community-service/deployment.yaml | 2 +- .../services/db-service/deployment.yaml | 68 ++++++++++--------- .../services/popular-service/deployment.yaml | 2 +- .../services/search-service/deployment.yaml | 2 +- .../services/thread-service/deployment.yaml | 2 +- .../services/vote-service/deployment.yaml | 2 +- code/kubernetes/traefik/values.yaml | 8 +-- 10 files changed, 48 insertions(+), 46 deletions(-) diff --git a/code/kubernetes/grpc-gateway/deployment.yaml b/code/kubernetes/grpc-gateway/deployment.yaml index 5cb8167..4a4d34b 100644 --- a/code/kubernetes/grpc-gateway/deployment.yaml +++ b/code/kubernetes/grpc-gateway/deployment.yaml @@ -103,4 +103,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/scripts/create-cluster.sh b/code/kubernetes/scripts/create-cluster.sh index e20ed38..6a6ba76 100644 --- a/code/kubernetes/scripts/create-cluster.sh +++ b/code/kubernetes/scripts/create-cluster.sh @@ -3,7 +3,7 @@ set -e PROJECT_ID="threadit-api" CLUSTER_NAME="threadit-cluster" -MACHINE_TYPE="e2-standard-4" +MACHINE_TYPE="e2-medium" ZONE="europe-west1-b" gcloud config set project $PROJECT_ID @@ -16,7 +16,7 @@ gcloud container clusters create $CLUSTER_NAME \ --machine-type=$MACHINE_TYPE \ --zone=$ZONE \ --disk-type=pd-standard \ - --disk-size=20 + --disk-size=25 gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE diff --git a/code/kubernetes/services/comment-service/deployment.yaml b/code/kubernetes/services/comment-service/deployment.yaml index 691a5a8..7b4c8b8 100644 --- a/code/kubernetes/services/comment-service/deployment.yaml +++ b/code/kubernetes/services/comment-service/deployment.yaml @@ -73,4 +73,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/community-service/deployment.yaml b/code/kubernetes/services/community-service/deployment.yaml index d0cc0a6..d43b57c 100644 --- a/code/kubernetes/services/community-service/deployment.yaml +++ b/code/kubernetes/services/community-service/deployment.yaml @@ -73,4 +73,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/db-service/deployment.yaml b/code/kubernetes/services/db-service/deployment.yaml index 5c35074..09beca7 100644 --- a/code/kubernetes/services/db-service/deployment.yaml +++ b/code/kubernetes/services/db-service/deployment.yaml @@ -20,11 +20,11 @@ spec: - containerPort: 50051 resources: requests: - cpu: 30m - memory: 60Mi + cpu: 100m + memory: 200Mi limits: - cpu: 120m - memory: 240Mi + cpu: 200m + memory: 2Gi env: - name: SERVICE_PORT valueFrom: @@ -42,16 +42,17 @@ spec: - mountPath: /var/secret/gcp/ name: bucket-credentials readOnly: true - readinessProbe: - tcpSocket: - port: 50051 - initialDelaySeconds: 8 - timeoutSeconds: 5 - livenessProbe: - tcpSocket: - port: 50051 - initialDelaySeconds: 8 - timeoutSeconds: 5 +# TODO this might be causing this service to crash +# readinessProbe: +# tcpSocket: +# port: 50051 +# initialDelaySeconds: 8 +# timeoutSeconds: 5 +# livenessProbe: +# tcpSocket: +# port: 50051 +# initialDelaySeconds: 8 +# timeoutSeconds: 5 volumes: - name: bucket-credentials secret: @@ -59,22 +60,23 @@ spec: items: - key: gcs-key.json path: gcs-key.json ---- -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: db-service-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: db-service - minReplicas: 1 - maxReplicas: 3 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 60 \ No newline at end of file +# TODO this might be causing this service to crash +#--- +#apiVersion: autoscaling/v2 +#kind: HorizontalPodAutoscaler +#metadata: +# name: db-service-hpa +#spec: +# scaleTargetRef: +# apiVersion: apps/v1 +# kind: Deployment +# name: db-service +# minReplicas: 1 +# maxReplicas: 3 +# metrics: +# - type: Resource +# resource: +# name: cpu +# target: +# type: Utilization +# averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/popular-service/deployment.yaml b/code/kubernetes/services/popular-service/deployment.yaml index adb7d9e..84e6d57 100644 --- a/code/kubernetes/services/popular-service/deployment.yaml +++ b/code/kubernetes/services/popular-service/deployment.yaml @@ -73,4 +73,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/search-service/deployment.yaml b/code/kubernetes/services/search-service/deployment.yaml index 1ac1d49..ad29cb3 100644 --- a/code/kubernetes/services/search-service/deployment.yaml +++ b/code/kubernetes/services/search-service/deployment.yaml @@ -73,4 +73,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/thread-service/deployment.yaml b/code/kubernetes/services/thread-service/deployment.yaml index 86fcbd9..c8165ad 100644 --- a/code/kubernetes/services/thread-service/deployment.yaml +++ b/code/kubernetes/services/thread-service/deployment.yaml @@ -73,4 +73,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/vote-service/deployment.yaml b/code/kubernetes/services/vote-service/deployment.yaml index 97325cd..dabffb4 100644 --- a/code/kubernetes/services/vote-service/deployment.yaml +++ b/code/kubernetes/services/vote-service/deployment.yaml @@ -73,4 +73,4 @@ spec: name: cpu target: type: Utilization - averageUtilization: 60 \ No newline at end of file + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/traefik/values.yaml b/code/kubernetes/traefik/values.yaml index 504a34c..766d276 100644 --- a/code/kubernetes/traefik/values.yaml +++ b/code/kubernetes/traefik/values.yaml @@ -4,11 +4,11 @@ replicaCount: 1 resources: requests: - cpu: 20m - memory: 40Mi + cpu: 30m + memory: 60Mi limits: - cpu: 100m - memory: 100Mi + cpu: 120m + memory: 240Mi # TODO: If needed, uncomment and configure HPA settings #autoscaling: From afd2dbc333643a043442aa24d956b07217e200f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Proen=C3=A7a?= Date: Tue, 27 May 2025 23:27:19 +0100 Subject: [PATCH 7/7] Resources configuration done. Fixed db-service probe race condition --- code/kubernetes/grpc-gateway/deployment.yaml | 6 +- code/kubernetes/mongo/deployment.yaml | 6 +- code/kubernetes/scripts/README.md | 1 + code/kubernetes/scripts/cluster-info.sh | 23 +------ code/kubernetes/scripts/create-cluster.sh | 6 +- .../services/comment-service/deployment.yaml | 12 ++-- .../community-service/deployment.yaml | 12 ++-- .../services/db-service/deployment.yaml | 69 ++++++++++--------- .../services/popular-service/deployment.yaml | 12 ++-- .../services/search-service/deployment.yaml | 12 ++-- .../services/thread-service/deployment.yaml | 12 ++-- .../services/vote-service/deployment.yaml | 12 ++-- code/kubernetes/traefik/values.yaml | 4 +- 13 files changed, 85 insertions(+), 102 deletions(-) diff --git a/code/kubernetes/grpc-gateway/deployment.yaml b/code/kubernetes/grpc-gateway/deployment.yaml index 4a4d34b..529ff7f 100644 --- a/code/kubernetes/grpc-gateway/deployment.yaml +++ b/code/kubernetes/grpc-gateway/deployment.yaml @@ -20,8 +20,8 @@ spec: - containerPort: 8080 resources: requests: - cpu: 30m - memory: 60Mi + cpu: 40m + memory: 80Mi limits: cpu: 120m memory: 240Mi @@ -83,7 +83,7 @@ spec: httpGet: path: /health port: 8080 - initialDelaySeconds: 10 + initialDelaySeconds: 30 timeoutSeconds: 5 --- apiVersion: autoscaling/v2 diff --git a/code/kubernetes/mongo/deployment.yaml b/code/kubernetes/mongo/deployment.yaml index a68ce41..3810484 100644 --- a/code/kubernetes/mongo/deployment.yaml +++ b/code/kubernetes/mongo/deployment.yaml @@ -19,7 +19,7 @@ spec: - containerPort: 27017 resources: requests: - cpu: 150m + cpu: 200m memory: 700Mi limits: cpu: 500m @@ -49,7 +49,7 @@ spec: - mongosh - --eval - "db.adminCommand('ping')" - initialDelaySeconds: 15 + initialDelaySeconds: 60 timeoutSeconds: 5 readinessProbe: exec: @@ -57,7 +57,7 @@ spec: - mongosh - --eval - "db.adminCommand('ping')" - initialDelaySeconds: 15 + initialDelaySeconds: 20 timeoutSeconds: 5 volumes: - name: mongodb-data diff --git a/code/kubernetes/scripts/README.md b/code/kubernetes/scripts/README.md index 0716185..c44a3d7 100644 --- a/code/kubernetes/scripts/README.md +++ b/code/kubernetes/scripts/README.md @@ -45,6 +45,7 @@ $ ./cluster-info.sh - `--deployments` Shows deployment configurations and statuses for the namespace. - `--resources-pods` Displays real-time CPU and memory usage metrics for each pod. - `--resources-nodes` Displays real-time CPU and memory usage metrics for each node in the cluster. +- `--hpa` Shows all Horizontal Pod Autoscalers in the namespace, including current and target scaling metrics. - `--all` Runs all of the above commands to display full cluster info. ### 4. Delete Cluster diff --git a/code/kubernetes/scripts/cluster-info.sh b/code/kubernetes/scripts/cluster-info.sh index 6301967..5d56aa5 100644 --- a/code/kubernetes/scripts/cluster-info.sh +++ b/code/kubernetes/scripts/cluster-info.sh @@ -12,8 +12,6 @@ SHOW_DEPLOYMENTS=false SHOW_RESOURCES_PODS=false SHOW_RESOURCES_NODES=false SHOW_HPA=false -SHOW_DETAILED_RESOURCES=false -SHOW_EVENTS=false if [[ $# -eq 0 ]]; then SHOW_NAMESPACES=true @@ -23,8 +21,6 @@ if [[ $# -eq 0 ]]; then SHOW_RESOURCES_PODS=true SHOW_RESOURCES_NODES=true SHOW_HPA=true - SHOW_DETAILED_RESOURCES=true - SHOW_EVENTS=true fi # Parse flags @@ -37,8 +33,6 @@ while [[ "$#" -gt 0 ]]; do --resources-pods) SHOW_RESOURCES_PODS=true ;; --resources-nodes) SHOW_RESOURCES_NODES=true ;; --hpa) SHOW_HPA=true ;; - --detailed-resources) SHOW_DETAILED_RESOURCES=true ;; - --events) SHOW_EVENTS=true ;; --all) SHOW_NAMESPACES=true SHOW_PODS=true @@ -47,8 +41,6 @@ while [[ "$#" -gt 0 ]]; do SHOW_RESOURCES_PODS=true SHOW_RESOURCES_NODES=true SHOW_HPA=true - SHOW_DETAILED_RESOURCES=true - SHOW_EVENTS=true ;; *) echo "āŒ Unknown flag: $1"; exit 1 ;; esac @@ -65,17 +57,4 @@ $SHOW_SERVICES && echo -e "\nšŸ” Services:" && kubectl get svc -n $CLUSTER_NAME $SHOW_DEPLOYMENTS && echo -e "\nšŸ“‚ Deployments:" && kubectl get deployments -n $CLUSTER_NAME $SHOW_RESOURCES_PODS && echo -e "\nšŸ“Š Resource Usage (Pods):" && kubectl top pods -n $CLUSTER_NAME $SHOW_RESOURCES_NODES && echo -e "\nšŸ–„ļø Resource Usage (Nodes):" && kubectl top nodes - -# New sections for monitoring HPAs and resource limits -$SHOW_HPA && echo -e "\nāš–ļø Horizontal Pod Autoscalers:" && kubectl get hpa -n $CLUSTER_NAME - -if $SHOW_DETAILED_RESOURCES; then - echo -e "\nšŸ”Ž Detailed Resource Limits and Requests:" - echo "-------------------------------------------" - for pod in $(kubectl get pods -n $CLUSTER_NAME -o=name); do - echo -e "\nšŸ“Œ $pod" - kubectl describe $pod -n $CLUSTER_NAME | grep -A8 "Limits:" | grep -v "Node:" - done -fi - -$SHOW_EVENTS && echo -e "\nšŸ“œ Recent Events (including scaling):" && kubectl get events -n $CLUSTER_NAME --sort-by='.lastTimestamp' | grep -E '(HorizontalPodAutoscaler|scale|Scaled)' \ No newline at end of file +$SHOW_HPA && echo -e "\nšŸ“Œ Horizontal Pod Autoscalers:" && kubectl get hpa -n $CLUSTER_NAME \ No newline at end of file diff --git a/code/kubernetes/scripts/create-cluster.sh b/code/kubernetes/scripts/create-cluster.sh index 6a6ba76..a5b0b19 100644 --- a/code/kubernetes/scripts/create-cluster.sh +++ b/code/kubernetes/scripts/create-cluster.sh @@ -3,7 +3,7 @@ set -e PROJECT_ID="threadit-api" CLUSTER_NAME="threadit-cluster" -MACHINE_TYPE="e2-medium" +MACHINE_TYPE="e2-standard-2" ZONE="europe-west1-b" gcloud config set project $PROJECT_ID @@ -11,8 +11,8 @@ gcloud config set project $PROJECT_ID gcloud container clusters create $CLUSTER_NAME \ --num-nodes=3 \ --enable-autoscaling \ - --min-nodes=0 \ - --max-nodes=4 \ + --min-nodes=1 \ + --max-nodes=5 \ --machine-type=$MACHINE_TYPE \ --zone=$ZONE \ --disk-type=pd-standard \ diff --git a/code/kubernetes/services/comment-service/deployment.yaml b/code/kubernetes/services/comment-service/deployment.yaml index 7b4c8b8..9bd770e 100644 --- a/code/kubernetes/services/comment-service/deployment.yaml +++ b/code/kubernetes/services/comment-service/deployment.yaml @@ -23,8 +23,8 @@ spec: cpu: 20m memory: 40Mi limits: - cpu: 100m - memory: 200Mi + cpu: 60m + memory: 120Mi env: - name: SERVICE_PORT valueFrom: @@ -48,13 +48,13 @@ spec: readinessProbe: tcpSocket: port: 50054 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 5 + timeoutSeconds: 3 livenessProbe: tcpSocket: port: 50054 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 15 + timeoutSeconds: 3 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/code/kubernetes/services/community-service/deployment.yaml b/code/kubernetes/services/community-service/deployment.yaml index d43b57c..598daed 100644 --- a/code/kubernetes/services/community-service/deployment.yaml +++ b/code/kubernetes/services/community-service/deployment.yaml @@ -23,8 +23,8 @@ spec: cpu: 20m memory: 40Mi limits: - cpu: 100m - memory: 200Mi + cpu: 60m + memory: 120Mi env: - name: SERVICE_PORT valueFrom: @@ -48,13 +48,13 @@ spec: readinessProbe: tcpSocket: port: 50052 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 5 + timeoutSeconds: 3 livenessProbe: tcpSocket: port: 50052 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 15 + timeoutSeconds: 3 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/code/kubernetes/services/db-service/deployment.yaml b/code/kubernetes/services/db-service/deployment.yaml index 09beca7..cbf045f 100644 --- a/code/kubernetes/services/db-service/deployment.yaml +++ b/code/kubernetes/services/db-service/deployment.yaml @@ -21,9 +21,9 @@ spec: resources: requests: cpu: 100m - memory: 200Mi + memory: 250Mi limits: - cpu: 200m + cpu: 300m memory: 2Gi env: - name: SERVICE_PORT @@ -42,17 +42,21 @@ spec: - mountPath: /var/secret/gcp/ name: bucket-credentials readOnly: true -# TODO this might be causing this service to crash -# readinessProbe: -# tcpSocket: -# port: 50051 -# initialDelaySeconds: 8 -# timeoutSeconds: 5 -# livenessProbe: -# tcpSocket: -# port: 50051 -# initialDelaySeconds: 8 -# timeoutSeconds: 5 + livenessProbe: + tcpSocket: + port: 50051 + initialDelaySeconds: 60 + timeoutSeconds: 4 + readinessProbe: + tcpSocket: + port: 50051 + initialDelaySeconds: 30 + timeoutSeconds: 4 + startupProbe: + tcpSocket: + port: 50051 + periodSeconds: 2 + failureThreshold: 90 volumes: - name: bucket-credentials secret: @@ -60,23 +64,22 @@ spec: items: - key: gcs-key.json path: gcs-key.json -# TODO this might be causing this service to crash -#--- -#apiVersion: autoscaling/v2 -#kind: HorizontalPodAutoscaler -#metadata: -# name: db-service-hpa -#spec: -# scaleTargetRef: -# apiVersion: apps/v1 -# kind: Deployment -# name: db-service -# minReplicas: 1 -# maxReplicas: 3 -# metrics: -# - type: Resource -# resource: -# name: cpu -# target: -# type: Utilization -# averageUtilization: 80 \ No newline at end of file +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: db-service-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: db-service + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 80 \ No newline at end of file diff --git a/code/kubernetes/services/popular-service/deployment.yaml b/code/kubernetes/services/popular-service/deployment.yaml index 84e6d57..e6daa04 100644 --- a/code/kubernetes/services/popular-service/deployment.yaml +++ b/code/kubernetes/services/popular-service/deployment.yaml @@ -23,8 +23,8 @@ spec: cpu: 20m memory: 40Mi limits: - cpu: 100m - memory: 200Mi + cpu: 60m + memory: 120Mi env: - name: SERVICE_PORT valueFrom: @@ -48,13 +48,13 @@ spec: readinessProbe: tcpSocket: port: 50057 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 5 + timeoutSeconds: 3 livenessProbe: tcpSocket: port: 50057 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 15 + timeoutSeconds: 3 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/code/kubernetes/services/search-service/deployment.yaml b/code/kubernetes/services/search-service/deployment.yaml index ad29cb3..e51dae7 100644 --- a/code/kubernetes/services/search-service/deployment.yaml +++ b/code/kubernetes/services/search-service/deployment.yaml @@ -23,8 +23,8 @@ spec: cpu: 20m memory: 40Mi limits: - cpu: 100m - memory: 200Mi + cpu: 60m + memory: 120Mi env: - name: SERVICE_PORT valueFrom: @@ -48,13 +48,13 @@ spec: readinessProbe: tcpSocket: port: 50056 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 5 + timeoutSeconds: 3 livenessProbe: tcpSocket: port: 50056 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 15 + timeoutSeconds: 3 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/code/kubernetes/services/thread-service/deployment.yaml b/code/kubernetes/services/thread-service/deployment.yaml index c8165ad..11b9ee9 100644 --- a/code/kubernetes/services/thread-service/deployment.yaml +++ b/code/kubernetes/services/thread-service/deployment.yaml @@ -23,8 +23,8 @@ spec: cpu: 20m memory: 40Mi limits: - cpu: 100m - memory: 200Mi + cpu: 60m + memory: 120Mi env: - name: SERVICE_PORT valueFrom: @@ -48,13 +48,13 @@ spec: readinessProbe: tcpSocket: port: 50053 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 5 + timeoutSeconds: 3 livenessProbe: tcpSocket: port: 50053 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 15 + timeoutSeconds: 3 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/code/kubernetes/services/vote-service/deployment.yaml b/code/kubernetes/services/vote-service/deployment.yaml index dabffb4..44b329e 100644 --- a/code/kubernetes/services/vote-service/deployment.yaml +++ b/code/kubernetes/services/vote-service/deployment.yaml @@ -23,8 +23,8 @@ spec: cpu: 20m memory: 40Mi limits: - cpu: 100m - memory: 200Mi + cpu: 60m + memory: 120Mi env: - name: SERVICE_PORT valueFrom: @@ -48,13 +48,13 @@ spec: readinessProbe: tcpSocket: port: 50055 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 5 + timeoutSeconds: 3 livenessProbe: tcpSocket: port: 50055 - initialDelaySeconds: 6 - timeoutSeconds: 4 + initialDelaySeconds: 15 + timeoutSeconds: 3 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler diff --git a/code/kubernetes/traefik/values.yaml b/code/kubernetes/traefik/values.yaml index 766d276..56f8925 100644 --- a/code/kubernetes/traefik/values.yaml +++ b/code/kubernetes/traefik/values.yaml @@ -4,8 +4,8 @@ replicaCount: 1 resources: requests: - cpu: 30m - memory: 60Mi + cpu: 40m + memory: 80Mi limits: cpu: 120m memory: 240Mi