Scaling Up/Down kubernetes deployments using only cronjobs and Service Accounts

147 views Asked by At

I've a workload that requires some deployments to be scaled up/down at certain hours of the day. Since the load is predictable, I didn't want to spend much time setting up HPA because it's a total overkill.

I'm using this service account and roles to assign the cronjob with the right permissions, but unexpecetly I'm getting errors on the scaling part of the process, not the permissionship.

This is the ServiceAccount/Role/Binding yamls

apiVersion: v1
kind: ServiceAccount
metadata:
  name: scaling-service-account
  namespace: myspace
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: scaling-cluster-role
  namespace: myspace
rules:
- apiGroups: ["apps"]
  resources: ["deployments/scale"]
  verbs: ["patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: scaling-cluster-role-binding
subjects:
- kind: ServiceAccount
  name: scaling-service-account
  namespace: myspace
roleRef:
  kind: ClusterRole
  name: scaling-cluster-role
  apiGroup: rbac.authorization.k8s.io

And this is my cronjob:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: scale-up-job
  namespace: myspace
spec:
  schedule: "40 15 * * 1-5"
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 1
  successfulJobsHistoryLimit: 1
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        spec:
          containers:
          - name: kubectl
            image: bitnami/kubectl:latest
            imagePullPolicy: IfNotPresent
            args:
              - scale
              - deployment
              - mydeployment   
              - --namespace=myspace
              - --replicas=3
          serviceAccountName: scaling-service-account
          restartPolicy: Never

But when launched, the output of the pod points like the image didn't pass the right arguments or something totally separated from the permissionship part:

error: no objects passed to scale

Any ideas? :(

0

There are 0 answers