forked from kubernetes-sigs/cluster-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoscaler-to-workload-workload.yaml
More file actions
222 lines (222 loc) · 5.95 KB
/
Copy pathautoscaler-to-workload-workload.yaml
File metadata and controls
222 lines (222 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# This yaml deploys the autoscaler on a workload cluster and configures it to match
# against the corresponding Cluster API cluster which is defined into the management cluster.
---
apiVersion: v1
kind: Namespace
metadata:
name: cluster-autoscaler-system
labels:
pod-security.kubernetes.io/enforce: privileged
pod-security.kubernetes.io/warn: privileged
pod-security.kubernetes.io/audit: privileged
---
# Specify kubeconfig for management cluster
apiVersion: v1
kind: Secret
metadata:
name: kubeconfig-management-cluster
namespace: cluster-autoscaler-system
stringData:
kubeconfig: |
apiVersion: v1
kind: Config
clusters:
- name: management-cluster
cluster:
certificate-authority-data: ${MANAGEMENT_CLUSTER_CA}
server: ${MANAGEMENT_CLUSTER_ADDRESS}
contexts:
- name: management-context
context:
cluster: management-cluster
namespace: ${CLUSTER_NAMESPACE}
user: cluster-autoscaler-sa
current-context: management-context
users:
- name: cluster-autoscaler-sa
user:
token: "${MANAGEMENT_CLUSTER_TOKEN}"
---
# Defines the service used by the cluster autoscaler and gives it
# RBAC permissions to look at all the workloads running in this cluster.
apiVersion: v1
kind: ServiceAccount
metadata:
name: cluster-autoscaler
namespace: cluster-autoscaler-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-autoscaler-workload
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-autoscaler-workload
subjects:
- kind: ServiceAccount
name: cluster-autoscaler
namespace: cluster-autoscaler-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-autoscaler-workload
rules:
- apiGroups:
- ""
resources:
- namespaces
- persistentvolumeclaims
- persistentvolumes
- pods
- replicationcontrollers
- services
verbs:
- get
- list
- watch
- apiGroups:
- "storage.k8s.io"
resources:
- volumeattachments
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- update
- watch
- apiGroups:
- ""
resources:
- pods/eviction
verbs:
- create
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- list
- watch
- apiGroups:
- storage.k8s.io
resources:
- csinodes
- storageclasses
- csidrivers
- csistoragecapacities
verbs:
- get
- list
- watch
- apiGroups:
- batch
resources:
- jobs
verbs:
- list
- watch
- apiGroups:
- apps
resources:
- daemonsets
- replicasets
- statefulsets
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- delete
- get
- update
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- create
- get
- update
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cluster-autoscaler
namespace: cluster-autoscaler-system
labels:
app: cluster-autoscaler
spec:
selector:
matchLabels:
app: cluster-autoscaler
replicas: 1
template:
metadata:
labels:
app: cluster-autoscaler
spec:
containers:
- image: gcr.io/k8s-staging-autoscaling/cluster-autoscaler:v20250814-cluster-autoscaler-chart-9.50.1-4-ga9cb59fdd
name: cluster-autoscaler
command:
- /cluster-autoscaler
args:
- --cloud-provider=clusterapi
# Specify kubeconfig for management cluster
- --cloud-config=/management-cluster/kubeconfig
# Limit cluster autoscaler to only match against resources belonging to a single Cluster API cluster
- --node-group-auto-discovery=clusterapi:namespace=${CLUSTER_NAMESPACE},clusterName=${CLUSTER_NAME}
# Set a short scale down unneeded time, so we don't have to wait too long during e2e testing
- --scale-down-unneeded-time=1m
# Set a short scale down delay after add time, so we don't have to wait too long during e2e testing
- --scale-down-delay-after-add=1m
# Set a short scale down delay after delete time, so we don't have to wait too long during e2e testing
- --scale-down-delay-after-delete=1m
# Set a short scale down delay after failure time, so we don't have to wait too long during e2e testing
- --scale-down-delay-after-failure=1m
# Set a max nodes limit as safeguard so that the test does not scale up unbounded.
# Note: The E2E test should only go up to 4 (assuming it starts with a min node group size of 2).
# Using 6 for additional some buffer and to allow different starting min node group sizes.
- --max-nodes-total=6
# CABPK sets this taint on startup, so we should configure it here accordingly
- --startup-taint=node.cluster.x-k8s.io/uninitialized
# Set the log verbosity
- --v=4
volumeMounts:
- name: kubeconfig-management-cluster
mountPath: /management-cluster
readOnly: true
# Run the autoscaler on control plane Machines to avoid disruptions when scaling to 0.
nodeSelector:
node-role.kubernetes.io/control-plane: ""
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
operator: Exists
serviceAccountName: cluster-autoscaler
terminationGracePeriodSeconds: 10
volumes:
- name: kubeconfig-management-cluster
secret:
secretName: kubeconfig-management-cluster
optional: false