|
125 | 125 |
|
126 | 126 | `kubectl scale headroom example --replicas=2` |
127 | 127 |
|
| 128 | +## Advanced example - scale a headroom down from a Cron Job |
| 129 | + |
| 130 | +Imagine you wanted to scale down the headroom resource overnight. |
| 131 | + |
| 132 | +Here's an example of how Kubernetes-native resources can be used. |
| 133 | + |
| 134 | +```yaml |
| 135 | +kind: CronJob |
| 136 | +apiVersion: batch/v1 |
| 137 | +metadata: |
| 138 | + name: scale-headroom |
| 139 | + namespace: default |
| 140 | +spec: |
| 141 | + schedule: "0 0 * * * *" |
| 142 | + successfulJobsHistoryLimit: 5 # Keep 5 successful jobs |
| 143 | + failedJobsHistoryLimit: 1 # Keep 1 failed job |
| 144 | + jobTemplate: |
| 145 | + spec: |
| 146 | + template: |
| 147 | + spec: |
| 148 | + serviceAccountName: headroom-scaler |
| 149 | + restartPolicy: OnFailure |
| 150 | + containers: |
| 151 | + - name: kubectl |
| 152 | + image: alpine/k8s:1.33.3 # Or a specific version |
| 153 | + command: |
| 154 | + - "/bin/sh" |
| 155 | + - "-c" |
| 156 | + - | |
| 157 | + apk add --no-cache kubectl |
| 158 | + kubectl scale headroom/example --replicas=0 |
| 159 | +--- |
| 160 | +apiVersion: v1 |
| 161 | +kind: ServiceAccount |
| 162 | +metadata: |
| 163 | + name: headroom-scaler |
| 164 | + namespace: default # Or your target namespace |
| 165 | + |
| 166 | +--- |
| 167 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 168 | +kind: ClusterRoleBinding # Or RoleBinding if headroom controller is namespace scoped |
| 169 | +metadata: |
| 170 | + name: headroom-scaler-rb |
| 171 | + namespace: default |
| 172 | +subjects: |
| 173 | + - kind: ServiceAccount |
| 174 | + name: headroom-scaler |
| 175 | + namespace: default |
| 176 | +roleRef: |
| 177 | + kind: ClusterRole # Or Role if headroom controller is namespace scoped |
| 178 | + name: headroom-scaler-role |
| 179 | + apiGroup: rbac.authorization.k8s.io |
| 180 | + |
| 181 | +--- |
| 182 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 183 | +kind: ClusterRole # Or Role if headroom controller is namespace scoped |
| 184 | +metadata: |
| 185 | + name: headroom-scaler-role |
| 186 | + namespace: default |
| 187 | +rules: |
| 188 | + - apiGroups: ["openfaas.com"] |
| 189 | + resources: ["headrooms", "headrooms/scale"] |
| 190 | + verbs: ["get", "patch", "update"] |
| 191 | +``` |
| 192 | +
|
128 | 193 | ## Configuration |
129 | 194 |
|
130 | 195 | Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. |
|
0 commit comments