Kubectl Scale doesn't work when run from Job

Hello everyone.
Recently I’ve been facing a strange behavior of kubectl scale command.
In my current setup I need to turn off some crons and scale down some of the deployments before doing the upgrade, so I’m doing it using a Job with Helm pre-upgrade hook. This solution works just fine for the Cronjob, but I can’t make it work with the deployment.

The job is doing a bash script with a following loop:

 CONSUMERS=$(kubectl get deployment -n "$NAMESPACE" -o jsonpath='{.items[*].metadata.name}')
            for consumer in $CONSUMERS; do
              if [[ "$consumer" =~ ^consumer-.* ]]; then
                echo "Scaling down consumer: $consumer"
                kubectl scale --replicas=0 -n $NAMESPACE deployment/$consumer
              else
                echo "Skipping deployment: $consumer"
              fi
            done

So the logic is that it should get the list of all the deployments within a namespace and scale down all the deployments which names are starting with a keyword consumer, but what I’m getting is this:

Scaling down consumer: consumer-test
error: no objects passed to scale 
Scaling down consumer: consumer-test1
error: no objects passed to scale 
Scaling down consumer: consumer-test2
error: no objects passed to scale 
Scaling down consumer: consumer-test3
error: no objects passed to scale 
Scaling down consumer: consumer-test4
error: no objects passed to scale 
Scaling down consumer: consumer-test5
error: no objects passed to scale 
Scaling down consumer: consumer-test6
error: no objects passed to scale 

The same exact script works just fine when I run it from my computer.

What’s even more interesting is that instead of using the loop, I’ve tried to hardcode the names of deployments, and it still was returing the exact same error error: no objects passed to scale

Does anyone have any idea what might be causing this issue?

Cluster information:

Kubernetes version: 1.29
Cloud being used: AWS

Hi,
Are you sure the pod that is trying to scale has sufficient permissions?