Skip to content

Commit be51b6f

Browse files
committed
feat: add monitoring script and update Helm templates for autoscaling and resource management
1 parent cf360e2 commit be51b6f

File tree

7 files changed

+203
-8
lines changed

7 files changed

+203
-8
lines changed

monitor-cluster-resources.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Script to monitor cluster resources during deployments
4+
# Usage: ./monitor-resources.sh
5+
6+
echo "🔍 Monitoring AKS cluster resources..."
7+
echo "=================================="
8+
9+
# Check node capacity and allocation
10+
echo "📊 Node Resource Capacity:"
11+
kubectl describe nodes | grep -E "(Name:|cpu:|memory:|Allocated resources)"
12+
13+
echo ""
14+
echo "📈 Current Resource Usage:"
15+
kubectl top nodes 2>/dev/null || echo "❌ Metrics server not available. Install with: kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml"
16+
17+
echo ""
18+
echo "🏃 Running Pods Resource Usage:"
19+
kubectl top pods --all-namespaces 2>/dev/null || echo "❌ Metrics server not available"
20+
21+
echo ""
22+
echo "🎯 Resource Requests vs Limits by Namespace:"
23+
kubectl describe nodes | grep -A 10 "Allocated resources"
24+
25+
echo ""
26+
echo "⚠️ Pending Pods (Resource constraints):"
27+
kubectl get pods --all-namespaces --field-selector=status.phase=Pending
28+
29+
echo ""
30+
echo "🔄 Current Deployments Status:"
31+
kubectl get deployments --all-namespaces
32+
33+
echo ""
34+
echo "📋 Horizontal Pod Autoscaler Status:"
35+
kubectl get hpa --all-namespaces
36+
37+
echo ""
38+
echo "🛡️ Pod Disruption Budgets:"
39+
kubectl get pdb --all-namespaces

my-chart/templates/hpa.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "my-chart.fullname" . }}-hpa-v1
6+
labels:
7+
{{- include "my-chart.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "my-chart.fullname" . }}-v1
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
---
33+
apiVersion: autoscaling/v2
34+
kind: HorizontalPodAutoscaler
35+
metadata:
36+
name: {{ include "my-chart.fullname" . }}-hpa-v2
37+
labels:
38+
{{- include "my-chart.labels" . | nindent 4 }}
39+
spec:
40+
scaleTargetRef:
41+
apiVersion: apps/v1
42+
kind: Deployment
43+
name: {{ include "my-chart.fullname" . }}-v2
44+
minReplicas: {{ .Values.autoscaling.minReplicas }}
45+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
46+
metrics:
47+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
48+
- type: Resource
49+
resource:
50+
name: cpu
51+
target:
52+
type: Utilization
53+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
54+
{{- end }}
55+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
56+
- type: Resource
57+
resource:
58+
name: memory
59+
target:
60+
type: Utilization
61+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
62+
{{- end }}
63+
{{- end }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: {{ include "my-chart.fullname" . }}-spring-app-pdb
5+
labels:
6+
{{- include "my-chart.labels" . | nindent 4 }}
7+
spec:
8+
minAvailable: 1
9+
selector:
10+
matchLabels:
11+
app: spring-app
12+
{{- include "my-chart.selectorLabels" . | nindent 6 }}
13+
---
14+
apiVersion: policy/v1
15+
kind: PodDisruptionBudget
16+
metadata:
17+
name: {{ include "my-chart.fullname" . }}-postgres-pdb
18+
labels:
19+
{{- include "my-chart.labels" . | nindent 4 }}
20+
spec:
21+
minAvailable: 1
22+
selector:
23+
matchLabels:
24+
app: postgres-database
25+
{{- include "my-chart.selectorLabels" . | nindent 6 }}
26+
---
27+
apiVersion: policy/v1
28+
kind: PodDisruptionBudget
29+
metadata:
30+
name: {{ include "my-chart.fullname" . }}-redis-pdb
31+
labels:
32+
{{- include "my-chart.labels" . | nindent 4 }}
33+
spec:
34+
minAvailable: 1
35+
selector:
36+
matchLabels:
37+
app: redis-database
38+
{{- include "my-chart.selectorLabels" . | nindent 6 }}

my-chart/templates/spring-app-deployment-v1.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ metadata:
66
{{- include "my-chart.labels" . | nindent 4 }}
77
spec:
88
replicas: {{ .Values.v1.replicas }}
9+
strategy:
10+
type: RollingUpdate
11+
rollingUpdate:
12+
maxSurge: 1
13+
maxUnavailable: 0
914
selector:
1015
matchLabels:
1116
app: spring-app
@@ -38,6 +43,22 @@ spec:
3843
name: spring-app-container
3944
ports:
4045
- containerPort: 8086
46+
livenessProbe:
47+
httpGet:
48+
path: /actuator/health
49+
port: 8086
50+
initialDelaySeconds: 60
51+
periodSeconds: 30
52+
timeoutSeconds: 5
53+
failureThreshold: 3
54+
readinessProbe:
55+
httpGet:
56+
path: /actuator/health
57+
port: 8086
58+
initialDelaySeconds: 30
59+
periodSeconds: 10
60+
timeoutSeconds: 5
61+
failureThreshold: 3
4162
resources:
4263
limits:
4364
cpu: {{ .Values.v1.springAppContainer.resources.limits.cpu }}

my-chart/templates/spring-app-deployment-v2.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ metadata:
66
{{- include "my-chart.labels" . | nindent 4 }}
77
spec:
88
replicas: {{ .Values.v2.replicas }}
9+
strategy:
10+
type: RollingUpdate
11+
rollingUpdate:
12+
maxSurge: 1
13+
maxUnavailable: 0
914
selector:
1015
matchLabels:
1116
app: spring-app
@@ -36,6 +41,22 @@ spec:
3641
name: spring-app-container
3742
ports:
3843
- containerPort: 8086
44+
livenessProbe:
45+
httpGet:
46+
path: /actuator/health
47+
port: 8086
48+
initialDelaySeconds: 60
49+
periodSeconds: 30
50+
timeoutSeconds: 5
51+
failureThreshold: 3
52+
readinessProbe:
53+
httpGet:
54+
path: /actuator/health
55+
port: 8086
56+
initialDelaySeconds: 30
57+
periodSeconds: 10
58+
timeoutSeconds: 5
59+
failureThreshold: 3
3960
resources:
4061
limits:
4162
cpu: {{ .Values.v2.springAppContainer.resources.limits.cpu }}

my-chart/values.yaml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
# Rolling update configuration
2+
rollingUpdate:
3+
maxSurge: 1
4+
maxUnavailable: 0
5+
6+
# Horizontal Pod Autoscaler configuration
7+
autoscaling:
8+
enabled: true
9+
minReplicas: 2
10+
maxReplicas: 6
11+
targetCPUUtilizationPercentage: 70
12+
targetMemoryUtilizationPercentage: 80
13+
114
v1:
2-
replicas: 1
15+
replicas: 2 # Increased for better availability during updates
316
springAppContainer:
417
env:
518
changelogVersion: changelog_version-3.3.xml
@@ -14,10 +27,10 @@ v1:
1427
resources:
1528
limits:
1629
cpu: "1"
17-
memory: 512Mi
30+
memory: 768Mi # Increased memory limit
1831
requests:
19-
cpu: 125m
20-
memory: 128Mi
32+
cpu: 250m # Increased CPU request for better performance
33+
memory: 256Mi # Increased memory request
2134
v2:
2235
replicas: 2
2336
springAppContainer:
@@ -34,10 +47,10 @@ v2:
3447
resources:
3548
limits:
3649
cpu: "1"
37-
memory: 512Mi
50+
memory: 768Mi # Increased memory limit
3851
requests:
39-
cpu: 125m
40-
memory: 128Mi
52+
cpu: 250m # Increased CPU request for better performance
53+
memory: 256Mi # Increased memory request
4154
kubernetesClusterDomain: cluster.local
4255
postgresConfig:
4356
POSTGRES_DB: postgresdb

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ spring.redis.port=6379
1515
# spring.data.jpa.repositories.enabled=false
1616
# spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
1717
spring.jpa.hibernate.ddl-auto=none
18-
enableSearchFeature=false
18+
enableSearchFeature=true

0 commit comments

Comments
 (0)