0

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? :(

1
  • Okey, problem was that at the role it was missing deployment as a resource, above from deployment/scale Commented Nov 17, 2023 at 13:19

1 Answer 1

1

Ok I have it. For if someone have the same problem, the config is:

rules:
  - apiGroups: ["apps"]
    resources: ["deployments", "deployments/scale"]
    verbs: ["get", "update", "patch"]
Sign up to request clarification or add additional context in comments.

1 Comment

Fixed my issue too, Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.