DEV Community

Hemanth B
Hemanth B

Posted on • Updated on

Scale down specific multiple deployments in kubernetes

In kubernetes, if there are multiple deployment like 5000 deployments deployed in kubernetes v1.20.0, and in that around 800 deployments where migrated from kubernetes v1.20.0 to v1.22.0,
When it need to scale down to zero only for 800 deployment.

We can use below shell script to scale down to zero for specific deployment.

First list 800 specific deployments details should be listed below in the deploy.list file

vi /tmp/deploy.list

abc-xyz-service
nyx-api-service
jkx-graphql-api-service
java-jws-service
dotnet-ams-service
xyz-python-service
...
Enter fullscreen mode Exit fullscreen mode

Execute below shell script to scale down the deployments to zero.

for pods in `cat /tmp/deploy.list`
do
    kubectl scale --replicas=0 $pods
done
Enter fullscreen mode Exit fullscreen mode

This should scale down the replicas of specific multiple deployments.

Discussion (0)