Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion code/kubernetes/grpc-gateway/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 8080
resources:
requests:
cpu: 40m
memory: 80Mi
limits:
cpu: 120m
memory: 240Mi
env:
- name: GRPC_GATEWAY_PORT
valueFrom:
Expand Down Expand Up @@ -76,5 +83,24 @@ spec:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
initialDelaySeconds: 30
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: 80
11 changes: 9 additions & 2 deletions code/kubernetes/mongo/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ spec:
image: mongo:latest
ports:
- containerPort: 27017
resources:
requests:
cpu: 200m
memory: 700Mi
limits:
cpu: 500m
memory: 1Gi
env:
- name: MONGO_INITDB_DATABASE
valueFrom:
Expand All @@ -42,15 +49,15 @@ spec:
- mongosh
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 15
initialDelaySeconds: 60
timeoutSeconds: 5
readinessProbe:
exec:
command:
- mongosh
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 15
initialDelaySeconds: 20
timeoutSeconds: 5
volumes:
- name: mongodb-data
Expand Down
1 change: 1 addition & 0 deletions code/kubernetes/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions code/kubernetes/scripts/cluster-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SHOW_SERVICES=false
SHOW_DEPLOYMENTS=false
SHOW_RESOURCES_PODS=false
SHOW_RESOURCES_NODES=false
SHOW_HPA=false

if [[ $# -eq 0 ]]; then
SHOW_NAMESPACES=true
Expand All @@ -19,6 +20,7 @@ if [[ $# -eq 0 ]]; then
SHOW_DEPLOYMENTS=true
SHOW_RESOURCES_PODS=true
SHOW_RESOURCES_NODES=true
SHOW_HPA=true
fi

# Parse flags
Expand All @@ -30,13 +32,15 @@ while [[ "$#" -gt 0 ]]; do
--deployments) SHOW_DEPLOYMENTS=true ;;
--resources-pods) SHOW_RESOURCES_PODS=true ;;
--resources-nodes) SHOW_RESOURCES_NODES=true ;;
--hpa) SHOW_HPA=true ;;
--all)
SHOW_NAMESPACES=true
SHOW_PODS=true
SHOW_SERVICES=true
SHOW_DEPLOYMENTS=true
SHOW_RESOURCES_PODS=true
SHOW_RESOURCES_NODES=true
SHOW_HPA=true
;;
*) echo "❌ Unknown flag: $1"; exit 1 ;;
esac
Expand All @@ -53,3 +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
$SHOW_HPA && echo -e "\n📌 Horizontal Pod Autoscalers:" && kubectl get hpa -n $CLUSTER_NAME
8 changes: 4 additions & 4 deletions code/kubernetes/scripts/create-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ set -e

PROJECT_ID="threadit-api"
CLUSTER_NAME="threadit-cluster"
MACHINE_TYPE="e2-standard-4"
MACHINE_TYPE="e2-standard-2"
ZONE="europe-west1-b"

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 \
--disk-size=20
--disk-size=25

gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE

Expand Down
34 changes: 30 additions & 4 deletions code/kubernetes/services/comment-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 50054
resources:
requests:
cpu: 20m
memory: 40Mi
limits:
cpu: 60m
memory: 120Mi
env:
- name: SERVICE_PORT
valueFrom:
Expand All @@ -41,10 +48,29 @@ 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
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: 80
34 changes: 30 additions & 4 deletions code/kubernetes/services/community-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 50052
resources:
requests:
cpu: 20m
memory: 40Mi
limits:
cpu: 60m
memory: 120Mi
env:
- name: SERVICE_PORT
valueFrom:
Expand All @@ -41,10 +48,29 @@ 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
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: 80
41 changes: 36 additions & 5 deletions code/kubernetes/services/db-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 50051
resources:
requests:
cpu: 100m
memory: 250Mi
limits:
cpu: 300m
memory: 2Gi
env:
- name: SERVICE_PORT
valueFrom:
Expand All @@ -35,20 +42,44 @@ spec:
- mountPath: /var/secret/gcp/
name: bucket-credentials
readOnly: true
livenessProbe:
tcpSocket:
port: 50051
initialDelaySeconds: 60
timeoutSeconds: 4
readinessProbe:
tcpSocket:
port: 50051
initialDelaySeconds: 8
timeoutSeconds: 5
livenessProbe:
initialDelaySeconds: 30
timeoutSeconds: 4
startupProbe:
tcpSocket:
port: 50051
initialDelaySeconds: 8
timeoutSeconds: 5
periodSeconds: 2
failureThreshold: 90
volumes:
- name: bucket-credentials
secret:
secretName: bucket-secret
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: 80
34 changes: 30 additions & 4 deletions code/kubernetes/services/popular-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ spec:
imagePullPolicy: Always
ports:
- containerPort: 50057
resources:
requests:
cpu: 20m
memory: 40Mi
limits:
cpu: 60m
memory: 120Mi
env:
- name: SERVICE_PORT
valueFrom:
Expand All @@ -41,10 +48,29 @@ 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
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: 80
Loading