Create eks node group label and taint
1labels = {
2 "node-group" : "spotInstances"
3}
4taints = [
5 {
6 effect = "NO_SCHEDULE"
7 key = "devops"
8 value = "forceSchedule"
9 }
10]
Create priorityClass one to placeholder other one to nornal schedule
1apiVersion: scheduling.k8s.io/v1
2kind: PriorityClass
3metadata:
4 name: placeholder
5value: 0
6preemptionPolicy: Never
7globalDefault: false
8description: 'placeholder'
9---
10apiVersion: scheduling.k8s.io/v1
11kind: PriorityClass
12metadata:
13 name: normal
14value: 1
15preemptionPolicy: Never
16globalDefault: true # default
17description: 'normal'
Use placeholde deployment
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: placeholder
5spec:
6 replicas: 1 # how many placeholder node should launch
7 selector:
8 matchLabels:
9 app: placeholder
10 template:
11 metadata:
12 labels:
13 app: placeholder
14 spec:
15 terminationGracePeriodSeconds: 0 # important
16 priorityClassName: placeholder # important
17 containers:
18 - image: nginx:1.23.1-alpine
19 name: placeholder
20 resources:
21 requests:
22 cpu: 3500m # this will use almost cpu
23 affinity:
24 nodeAffinity:
25 requiredDuringSchedulingIgnoredDuringExecution:
26 nodeSelectorTerms:
27 - matchExpressions:
28 - key: node-group
29 operator: In
30 values:
31 - spotInstances
32 tolerations:
33 - key: "devops"
34 operator: "Equal"
35 value: "forceSchedule"
36 effect: "NoSchedule"
Schedule the pod to placeholde node and evict the placholder pod and launch new placehole node
1apiVersion: v1
2kind: Pod
3spec:
4 affinity:
5 priorityClassName: normal
6 nodeAffinity:
7 requiredDuringSchedulingIgnoredDuringExecution:
8 nodeSelectorTerms:
9 - matchExpressions:
10 - key: node-group
11 operator: In
12 values:
13 - spotInstances
14 tolerations:
15 - key: "devops"
16 operator: "Equal"
17 value: "forceSchedule"
18 effect: "NoSchedule"
Reference