-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkube-scale.yaml
64 lines (58 loc) · 1.51 KB
/
kube-scale.yaml
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
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .DEPLOYMENT_NAME }}-scaler
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .DEPLOYMENT_NAME }}.scale
annotations:
rbac.authorization.kubernetes.io/autoupdate: "false"
rules:
- apiGroups: ["extensions", "apps"]
resources:
- deployments/scale
resourceNames:
- {{ .DEPLOYMENT_NAME }}
verbs:
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .DEPLOYMENT_NAME }}-scaler.{{ .DEPLOYMENT_NAME }}.scale
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ .DEPLOYMENT_NAME }}.scale
subjects:
- kind: ServiceAccount
name: {{ .DEPLOYMENT_NAME }}-scaler
---
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
name: {{ .DEPLOYMENT_NAME }}-autoscale-{{ lower (randAlphaNum 4) }}
labels:
app: {{ .DEPLOYMENT_NAME }}-autoscale
role: cron
spec:
schedule: {{ quote .CRON }}
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
serviceAccountName: {{ .DEPLOYMENT_NAME }}-scaler
containers:
- name: {{ .DEPLOYMENT_NAME }}-autoscale
image: {{ .IMAGE_NAME }}:{{ .IMAGE_TAG }}
imagePullPolicy: IfNotPresent
args: ["{{ .DEPLOYMENT_NAME }}", "{{ .REPLICAS }}"]
restartPolicy: OnFailure
{{ if isset "IMAGE_PULL_SECRET" }}
imagePullSecrets:
- name: {{ .IMAGE_PULL_SECRET}}
{{ end }}