Skip to content

Commit 0bd6850

Browse files
author
Anton Putra
authored
🤫 EKS Cluster Auto Scaling (antonputra#9)
1 parent 7f3c7e6 commit 0bd6850

File tree

6 files changed

+300
-0
lines changed

6 files changed

+300
-0
lines changed

‎lessons/070/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# How to Create GKE Cluster Using TERRAFORM from Scratch?
2+
3+
[YouTube Tutorial](https://youtu.be/XTcos7s0iDo)

‎lessons/070/eks.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
apiVersion: eksctl.io/v1alpha5
3+
kind: ClusterConfig
4+
metadata:
5+
name: antonputra
6+
region: us-east-1
7+
version: "1.20"
8+
availabilityZones:
9+
- us-east-1a
10+
- us-east-1b
11+
managedNodeGroups:
12+
- name: managed-nodes
13+
labels:
14+
role: managed-nodes
15+
instanceType: t3.medium
16+
minSize: 1
17+
maxSize: 10
18+
desiredCapacity: 1
19+
volumeSize: 20
20+
nodeGroups:
21+
- name: unmanaged-nodes
22+
labels:
23+
role: unmanaged-nodes
24+
instanceType: t3.medium
25+
minSize: 1
26+
maxSize: 10
27+
desiredCapacity: 1
28+
volumeSize: 20

‎lessons/070/iam-policy.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Action": [
6+
"autoscaling:DescribeAutoScalingGroups",
7+
"autoscaling:DescribeAutoScalingInstances",
8+
"autoscaling:DescribeLaunchConfigurations",
9+
"autoscaling:DescribeTags",
10+
"autoscaling:SetDesiredCapacity",
11+
"autoscaling:TerminateInstanceInAutoScalingGroup",
12+
"ec2:DescribeLaunchTemplateVersions"
13+
],
14+
"Resource": "*",
15+
"Effect": "Allow"
16+
}
17+
]
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
labels:
6+
k8s-addon: cluster-autoscaler.addons.k8s.io
7+
k8s-app: cluster-autoscaler
8+
annotations:
9+
eks.amazonaws.com/role-arn: arn:aws:iam::424432388155:role/AmazonEKSClusterAutoscalerRole
10+
name: cluster-autoscaler
11+
namespace: kube-system
12+
13+
---
14+
apiVersion: rbac.authorization.k8s.io/v1
15+
kind: ClusterRole
16+
metadata:
17+
name: cluster-autoscaler
18+
labels:
19+
k8s-addon: cluster-autoscaler.addons.k8s.io
20+
k8s-app: cluster-autoscaler
21+
rules:
22+
- apiGroups: [""]
23+
resources: ["events", "endpoints"]
24+
verbs: ["create", "patch"]
25+
- apiGroups: [""]
26+
resources: ["pods/eviction"]
27+
verbs: ["create"]
28+
- apiGroups: [""]
29+
resources: ["pods/status"]
30+
verbs: ["update"]
31+
- apiGroups: [""]
32+
resources: ["endpoints"]
33+
resourceNames: ["cluster-autoscaler"]
34+
verbs: ["get", "update"]
35+
- apiGroups: [""]
36+
resources: ["nodes"]
37+
verbs: ["watch", "list", "get", "update"]
38+
- apiGroups: [""]
39+
resources:
40+
- "pods"
41+
- "services"
42+
- "replicationcontrollers"
43+
- "persistentvolumeclaims"
44+
- "persistentvolumes"
45+
verbs: ["watch", "list", "get"]
46+
- apiGroups: ["extensions"]
47+
resources: ["replicasets", "daemonsets"]
48+
verbs: ["watch", "list", "get"]
49+
- apiGroups: ["policy"]
50+
resources: ["poddisruptionbudgets"]
51+
verbs: ["watch", "list"]
52+
- apiGroups: ["apps"]
53+
resources: ["statefulsets", "replicasets", "daemonsets"]
54+
verbs: ["watch", "list", "get"]
55+
- apiGroups: ["storage.k8s.io"]
56+
resources: ["storageclasses", "csinodes"]
57+
verbs: ["watch", "list", "get"]
58+
- apiGroups: ["batch", "extensions"]
59+
resources: ["jobs"]
60+
verbs: ["get", "list", "watch", "patch"]
61+
- apiGroups: ["coordination.k8s.io"]
62+
resources: ["leases"]
63+
verbs: ["create"]
64+
- apiGroups: ["coordination.k8s.io"]
65+
resourceNames: ["cluster-autoscaler"]
66+
resources: ["leases"]
67+
verbs: ["get", "update"]
68+
---
69+
apiVersion: rbac.authorization.k8s.io/v1
70+
kind: Role
71+
metadata:
72+
name: cluster-autoscaler
73+
namespace: kube-system
74+
labels:
75+
k8s-addon: cluster-autoscaler.addons.k8s.io
76+
k8s-app: cluster-autoscaler
77+
rules:
78+
- apiGroups: [""]
79+
resources: ["configmaps"]
80+
verbs: ["create","list","watch"]
81+
- apiGroups: [""]
82+
resources: ["configmaps"]
83+
resourceNames: ["cluster-autoscaler-status", "cluster-autoscaler-priority-expander"]
84+
verbs: ["delete", "get", "update", "watch"]
85+
86+
---
87+
apiVersion: rbac.authorization.k8s.io/v1
88+
kind: ClusterRoleBinding
89+
metadata:
90+
name: cluster-autoscaler
91+
labels:
92+
k8s-addon: cluster-autoscaler.addons.k8s.io
93+
k8s-app: cluster-autoscaler
94+
roleRef:
95+
apiGroup: rbac.authorization.k8s.io
96+
kind: ClusterRole
97+
name: cluster-autoscaler
98+
subjects:
99+
- kind: ServiceAccount
100+
name: cluster-autoscaler
101+
namespace: kube-system
102+
103+
---
104+
apiVersion: rbac.authorization.k8s.io/v1
105+
kind: RoleBinding
106+
metadata:
107+
name: cluster-autoscaler
108+
namespace: kube-system
109+
labels:
110+
k8s-addon: cluster-autoscaler.addons.k8s.io
111+
k8s-app: cluster-autoscaler
112+
roleRef:
113+
apiGroup: rbac.authorization.k8s.io
114+
kind: Role
115+
name: cluster-autoscaler
116+
subjects:
117+
- kind: ServiceAccount
118+
name: cluster-autoscaler
119+
namespace: kube-system
120+
121+
---
122+
apiVersion: apps/v1
123+
kind: Deployment
124+
metadata:
125+
name: cluster-autoscaler
126+
namespace: kube-system
127+
labels:
128+
app: cluster-autoscaler
129+
spec:
130+
replicas: 1
131+
selector:
132+
matchLabels:
133+
app: cluster-autoscaler
134+
template:
135+
metadata:
136+
labels:
137+
app: cluster-autoscaler
138+
annotations:
139+
cluster-autoscaler.kubernetes.io/safe-to-evict: 'false'
140+
spec:
141+
serviceAccountName: cluster-autoscaler
142+
containers:
143+
- image: k8s.gcr.io/autoscaling/cluster-autoscaler:v1.20.0
144+
name: cluster-autoscaler
145+
resources:
146+
limits:
147+
cpu: 100m
148+
memory: 300Mi
149+
requests:
150+
cpu: 100m
151+
memory: 300Mi
152+
# https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/aws/README.md
153+
command:
154+
- ./cluster-autoscaler
155+
- --v=4
156+
- --stderrthreshold=info
157+
- --cloud-provider=aws
158+
- --skip-nodes-with-local-storage=false
159+
- --expander=least-waste
160+
- --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/antonputra # Update cluster
161+
- --balance-similar-node-groups
162+
- --skip-nodes-with-system-pods=false
163+
volumeMounts:
164+
- name: ssl-certs
165+
mountPath: /etc/ssl/certs/ca-certificates.crt #/etc/ssl/certs/ca-bundle.crt for Amazon Linux Worker Nodes
166+
readOnly: true
167+
imagePullPolicy: "Always"
168+
volumes:
169+
- name: ssl-certs
170+
hostPath:
171+
path: "/etc/ssl/certs/ca-bundle.crt"
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-managed
5+
namespace: default
6+
spec:
7+
replicas: 2
8+
selector:
9+
matchLabels:
10+
app: nginx-managed
11+
template:
12+
metadata:
13+
labels:
14+
app: nginx-managed
15+
spec:
16+
containers:
17+
- name: nginx-managed
18+
image: nginx:1.14.2
19+
ports:
20+
- containerPort: 80
21+
affinity:
22+
nodeAffinity:
23+
requiredDuringSchedulingIgnoredDuringExecution:
24+
nodeSelectorTerms:
25+
- matchExpressions:
26+
- key: role
27+
operator: In
28+
values:
29+
- managed-nodes
30+
podAntiAffinity:
31+
requiredDuringSchedulingIgnoredDuringExecution:
32+
- labelSelector:
33+
matchExpressions:
34+
- key: app
35+
operator: In
36+
values:
37+
- nginx-managed
38+
topologyKey: kubernetes.io/hostname
39+
namespaces:
40+
- default
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-unmanaged
5+
namespace: default
6+
spec:
7+
replicas: 2
8+
selector:
9+
matchLabels:
10+
app: nginx-unmanaged
11+
template:
12+
metadata:
13+
labels:
14+
app: nginx-unmanaged
15+
spec:
16+
containers:
17+
- name: nginx-unmanaged
18+
image: nginx:1.14.2
19+
ports:
20+
- containerPort: 80
21+
affinity:
22+
nodeAffinity:
23+
requiredDuringSchedulingIgnoredDuringExecution:
24+
nodeSelectorTerms:
25+
- matchExpressions:
26+
- key: role
27+
operator: In
28+
values:
29+
- unmanaged-nodes
30+
podAntiAffinity:
31+
requiredDuringSchedulingIgnoredDuringExecution:
32+
- labelSelector:
33+
matchExpressions:
34+
- key: app
35+
operator: In
36+
values:
37+
- nginx-unmanaged
38+
topologyKey: kubernetes.io/hostname
39+
namespaces:
40+
- default

0 commit comments

Comments
 (0)