Skip to content

Commit e62ef4e

Browse files
committed
Add karpenter, node pool and node class
1 parent 2eddb81 commit e62ef4e

File tree

5 files changed

+149
-41
lines changed

5 files changed

+149
-41
lines changed

cluster.yaml

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ kind: ClusterConfig
33

44
metadata:
55
name: code4ro-prod
6-
region: eu-west-1
7-
version: "1.27"
8-
tags:
6+
region: eu-central-1
7+
version: "1.29"
8+
tags:
99
app: code4ro-k8s-prod
1010
env: production
11+
karpenter.sh/discovery: code4ro-k8s-prod
1112
vpc:
1213
publicAccessCIDRs: ["82.79.70.195/16"]
1314
clusterEndpoints:
14-
publicAccess: true
15+
publicAccess: true
1516
privateAccess: true
1617

1718
iamIdentityMappings:
@@ -22,8 +23,13 @@ iamIdentityMappings:
2223
username: admin
2324
noDuplicateARNs: true # prevents shadowing of ARNs
2425

26+
karpenter:
27+
version: "v0.35.4"
28+
createServiceAccount: true
29+
withSpotInterruptionQueue: true # adds all required policies and rules for supporting Spot Interruption Queue, default is false
30+
2531
iam:
26-
withOIDC: true
32+
withOIDC: true
2733
serviceAccounts:
2834
- metadata:
2935
name: aws-load-balancer-controller
@@ -43,9 +49,9 @@ addons:
4349
serviceAccountRoleARN: arn:aws:iam::172019762325:role/AmazonEKS_EBS_CSI_Driver
4450

4551
managedNodeGroups:
46-
- name: nodegroup1
52+
- name: nodegroup
4753
instanceType: t3a.medium
48-
availabilityZones: ["eu-west-1a"]
54+
availabilityZones: ["eu-central-1a"]
4955
iam:
5056
attachPolicyARNs:
5157
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
@@ -55,46 +61,14 @@ managedNodeGroups:
5561
- arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess
5662
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy # we need only this for viewing logs in Cloudwatch, the rest are there because we need the default https://eksctl.io/usage/iam-policies/#attaching-policies-by-arn
5763
withAddonPolicies:
58-
autoScaler: true
5964
awsLoadBalancerController: true
6065
cloudWatch: true
6166
ebs: true
6267
desiredCapacity: 2
63-
minSize: 2
64-
maxSize: 8
68+
minSize: 1
69+
maxSize: 3
6570
volumeSize: 20
6671
tags:
6772
nodegroup-role: worker
6873
app: code4ro-k8s-prod
6974
env: prod
70-
71-
- name: spot-pool1
72-
instanceTypes: ["t3a.medium", "t3.medium", "t3a.large", "t3.large", "t2.medium", "t2.large"]
73-
availabilityZones: ["eu-west-1a"]
74-
spot: true
75-
iam:
76-
attachPolicyARNs:
77-
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
78-
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
79-
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
80-
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
81-
- arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess
82-
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy # we need only this for viewing logs in Cloudwatch, the rest are there because we need the default https://eksctl.io/usage/iam-policies/#attaching-policies-by-arn
83-
withAddonPolicies:
84-
autoScaler: true
85-
awsLoadBalancerController: true
86-
cloudWatch: true
87-
ebs: true
88-
desiredCapacity: 1
89-
minSize: 0
90-
maxSize: 6
91-
volumeSize: 20
92-
labels: { nodegroup-role: spot, autoscaling: enabled }
93-
taints:
94-
- key: nodegroup-role
95-
value: spot
96-
effect: NoSchedule
97-
tags:
98-
nodegroup-role: spot
99-
app: code4ro-k8s-prod
100-
env: prod

infra/argo-apps/karpenter.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: karpenter
5+
namespace: argocd
6+
spec:
7+
project: infra
8+
sources:
9+
- path: infra/karpenter
10+
repoURL: https://github.com/code4romania/code4ro-k8s.git
11+
targetRevision: HEAD
12+
- chart: karpenter
13+
helm:
14+
valuesObject:
15+
settings:
16+
clusterName: code4ro-prod
17+
controller:
18+
resources:
19+
requests:
20+
cpu: 100m
21+
memory: 100M
22+
limits:
23+
cpu: 1
24+
memory: 1Gi
25+
serviceAccount:
26+
annotations:
27+
eks.amazonaws.com/role-arn: arn:aws:iam::172019762325:role/KarpenterControllerRole-code4ro-prod
28+
repoURL: public.ecr.aws/karpenter
29+
targetRevision: 0.35.4
30+
destination:
31+
namespace: karpenter
32+
server: https://kubernetes.default.svc
33+
syncPolicy:
34+
syncOptions:
35+
- CreateNamespace=true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: karpenter.k8s.aws/v1beta1
2+
kind: EC2NodeClass
3+
metadata:
4+
name: default
5+
annotations:
6+
kubernetes.io/description: "General purpose EC2NodeClass for running Amazon Linux 2 nodes"
7+
spec:
8+
amiFamily: AL2
9+
role: "KarpenterNodeRole-code4ro-prod"
10+
subnetSelectorTerms:
11+
- tags:
12+
karpenter.sh/discovery: "code4ro-prod"
13+
securityGroupSelectorTerms:
14+
- tags:
15+
karpenter.sh/discovery: "code4ro-prod"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: karpenter.sh/v1beta1
2+
kind: NodePool
3+
metadata:
4+
name: general-purpose
5+
annotations:
6+
kubernetes.io/description: "General purpose NodePool for generic workloads"
7+
spec:
8+
template:
9+
metadata:
10+
spec:
11+
labels:
12+
nodegroup-role: karpenter-worker
13+
app: code4ro-k8s-prod
14+
env: prod
15+
spec:
16+
requirements:
17+
- key: kubernetes.io/arch
18+
operator: In
19+
values: ["amd64"]
20+
- key: kubernetes.io/os
21+
operator: In
22+
values: ["linux"]
23+
- key: karpenter.sh/capacity-type
24+
operator: In
25+
values: ["on-demand"]
26+
- key: karpenter.k8s.aws/instance-category
27+
operator: In
28+
values: ["c", "m", "r"]
29+
- key: karpenter.k8s.aws/instance-generation
30+
operator: Gt
31+
values: ["2"]
32+
- key: "topology.kubernetes.io/zone"
33+
operator: In
34+
values: ["eu-central-1a"]
35+
nodeClassRef:
36+
name: default
37+
limits:
38+
resources:
39+
cpu: "80" # 10 instances * 8 vCPU
40+
memory: 320Gi # 10 instances * 32Gi

infra/karpenter/spot-node-pool.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: karpenter.sh/v1beta1
2+
kind: NodePool
3+
metadata:
4+
name: spot
5+
annotations:
6+
kubernetes.io/description: "NodePool for provisioning spot capacity"
7+
spec:
8+
template:
9+
metadata:
10+
spec:
11+
labels:
12+
nodegroup-role: karpenter-spot
13+
app: code4ro-k8s-prod
14+
env: prod
15+
spec:
16+
requirements:
17+
- key: karpenter.sh/capacity-type
18+
operator: In
19+
values: ["spot"]
20+
- key: kubernetes.io/arch
21+
operator: In
22+
values: ["amd64"]
23+
- key: kubernetes.io/os
24+
operator: In
25+
values: ["linux"]
26+
- key: karpenter.k8s.aws/instance-category
27+
operator: In
28+
values: ["c", "m", "r"]
29+
- key: karpenter.k8s.aws/instance-generation
30+
operator: Gt
31+
values: ["2"]
32+
- key: "topology.kubernetes.io/zone"
33+
operator: In
34+
values: ["eu-central-1a"]
35+
taints:
36+
- key: nodegroup-role
37+
effect: NoSchedule
38+
value: spot
39+
nodeClassRef:
40+
name: default
41+
limits:
42+
resources:
43+
cpu: "80" # 10 instances * 8 vCPU
44+
memory: 320Gi # 10 instances * 32Gi

0 commit comments

Comments
 (0)