Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale down Kubernetes pods

Tags:

kubernetes

I am using

kubectl scale --replicas=0 -f deployment.yaml

to stop all my running pods. Please let me know if there are better ways to bring down all running pods to Zero keeping configuration, deployments etc.. intact, so that I can scale up later as required.

like image 671
PPK Avatar asked Nov 30 '17 11:11

PPK


People also ask

How do you scale down pods in kubectl?

Scaling down to zero will stop your application. You can run kubectl scale --replicas=0, which will remove all the containers across the selected objects. You can scale back up again by repeating the command with a positive value.

Can you scale pods in Kubernetes?

Scaling overviewKubernetes also supports autoscaling of Pods, but it is outside of the scope of this tutorial. Scaling to zero is also possible, and it will terminate all Pods of the specified Deployment. Running multiple instances of an application will require a way to distribute the traffic to all of them.

How do you scale down a pod lens?

Click the pencil (Edit) Icon in the description banner to be presented with the YAML representation of the stack's StatefulSet. Scroll down if required to locate the replicas: field. To scale-down the Pods set this to 0 and then click Save & Close. To scale the Pods up, set this field to 1 or more.


4 Answers

You are doing the correct action; traditionally the scale verb is applied just to the resource name, as in kubectl scale deploy my-awesome-deployment --replicas=0, which removes the need to always point at the specific file that describes that deployment, but there's nothing wrong (that I know of) with using the file if that is more convenient for you.

like image 163
mdaniel Avatar answered Oct 11 '22 04:10

mdaniel


The solution is pretty easy and straightforward

kubectl scale deploy -n <namespace> --replicas=0 --all 
like image 41
Vivek Raveendran Avatar answered Oct 11 '22 02:10

Vivek Raveendran


Here we go. Scales down all deployments in a whole namespace:

kubectl get deploy -n <namespace> -o name | xargs -I % kubectl scale % --replicas=0 -n <namespace>

To scale up set --replicas=1 (or any other required number) accordingly

like image 27
R0MARI0 Avatar answered Oct 11 '22 02:10

R0MARI0


Use the following to scale down/up all deployments and stateful sets in the current namespace. Useful in development when switching projects.

kubectl scale statefulset,deployment --all --replicas=0

Add a namespace flag if needed

kubectl scale statefulset,deployment -n mynamespace --all --replicas=0
like image 10
timboslicecreative Avatar answered Oct 11 '22 04:10

timboslicecreative