Skip to content

Commit 54f0d5c

Browse files
committed
Added HPA in helm templates, EKS metric-server for HPA, and sync policy for helm
1 parent 3a550df commit 54f0d5c

File tree

5 files changed

+87
-16
lines changed

5 files changed

+87
-16
lines changed

Terraform/3-main.tf

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
module "vpc" {
2-
source = "./modules/vpc"
3-
4-
vpc_cidr = var.vpc_cidr
5-
availability_zones = var.availability_zones
6-
public_subnet_cidrs = var.public_subnet_cidrs
7-
private_subnet_cidrs = var.private_subnet_cidrs
8-
cluster_name = var.cluster_name
2+
source = "./modules/vpc"
3+
4+
vpc_cidr = var.vpc_cidr
5+
availability_zones = var.availability_zones
6+
public_subnet_cidrs = var.public_subnet_cidrs
7+
private_subnet_cidrs = var.private_subnet_cidrs
8+
cluster_name = var.cluster_name
99
}
1010

1111
module "eks" {
12-
source = "./modules/eks"
13-
14-
cluster_name = var.cluster_name
15-
cluster_version = var.cluster_version
16-
vpc_id = module.vpc.vpc_id
17-
subnet_ids = module.vpc.private_subnet_ids
18-
node_groups = var.node_groups
12+
source = "./modules/eks"
13+
14+
cluster_name = var.cluster_name
15+
cluster_version = var.cluster_version
16+
vpc_id = module.vpc.vpc_id
17+
subnet_ids = module.vpc.private_subnet_ids
18+
node_groups = var.node_groups
19+
}
20+
21+
# EKS Addon: metrics-server (enables HPA CPU/memory metrics)
22+
resource "aws_eks_addon" "metrics_server" {
23+
cluster_name = module.eks.cluster_name
24+
addon_name = "metrics-server"
25+
addon_version = null
26+
resolve_conflicts = "OVERWRITE"
1927
}

argocd/application.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ metadata:
66
spec:
77
project: default
88
source:
9-
repoURL: 'https://github.com/KarimZakzouk/Graduation-Project-Devops'
9+
repoURL: "https://github.com/KarimZakzouk/Graduation-Project-Devops"
1010
targetRevision: main
1111
path: helm
1212
helm:
1313
valueFiles:
1414
- values.yaml
15+
parameters:
16+
- name: namespace
17+
value: ${APP_NAMESPACE}
1518
destination:
1619
server: https://kubernetes.default.svc
1720
namespace: ${APP_NAMESPACE}
1821
syncPolicy:
1922
automated:
2023
prune: true
2124
selfHeal: true
25+
syncOptions:
26+
- CreateNamespace=true
27+
- PrunePropagationPolicy=foreground
28+
- ApplyOutOfSyncOnly=true
2229

2330
ignoreDifferences:
2431
- group: ""

helm/templates/deployment.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ kind: Deployment
33
metadata:
44
name: {{ .Release.Name }}
55
spec:
6+
{{- if not .Values.autoscaling.enabled }}
67
replicas: {{ .Values.replicaCount }}
8+
{{- end }}
79
selector:
810
matchLabels:
911
app: {{ .Release.Name }}
@@ -12,12 +14,21 @@ spec:
1214
labels:
1315
app: {{ .Release.Name }}
1416
spec:
17+
securityContext:
18+
runAsNonRoot: true
19+
seccompProfile:
20+
type: RuntimeDefault
1521
containers:
1622
- name: {{ .Release.Name }}
1723
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
1824
imagePullPolicy: {{ .Values.image.pullPolicy }}
1925
ports:
2026
- containerPort: {{ .Values.service.targetPort }}
27+
securityContext:
28+
allowPrivilegeEscalation: false
29+
capabilities:
30+
drop: ["ALL"]
31+
readOnlyRootFilesystem: true
2132
env:
2233
- name: MONGO_URI
2334
valueFrom:

helm/templates/hpa.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: autoscaling/v2
2+
3+
kind: HorizontalPodAutoscaler
4+
5+
metadata:
6+
name: {{ .Release.Name }}
7+
namespace: {{ .Release.Namespace }}
8+
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ .Release.Name }}
14+
15+
minReplicas: {{ .Values.autoscaling.minReplicas }}
16+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
17+
18+
metrics:
19+
- type: Resource
20+
resource:
21+
name: cpu
22+
target:
23+
type: Utilization
24+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}

helm/values.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ service:
1111
port: 80
1212
targetPort: 3000
1313

14-
namespace: ""
14+
namespace: ""
15+
16+
resources:
17+
requests:
18+
cpu: 100m
19+
memory: 128Mi
20+
limits:
21+
cpu: 500m
22+
memory: 512Mi
23+
24+
autoscaling:
25+
enabled: true
26+
minReplicas: 1
27+
maxReplicas: 10
28+
targetCPUUtilizationPercentage: 80
29+
targetMemoryUtilizationPercentage: 80

0 commit comments

Comments
 (0)