Goglides Dev 🌱

Balkrishna Pandey
Balkrishna Pandey

Posted on

How to scale up and down application pods using Kubernetes Deployment?

Kubernetes deployment is designed to help you with scaling applications up and down as per your need. Let's say you want to scale your application from 3 replicas to 10. You can do this by running the following command:


kubectl scale deployments nginx --replicas=10

Enter fullscreen mode Exit fullscreen mode

Let's verify,


kubectl get pods -l app=frontend

Enter fullscreen mode Exit fullscreen mode

You will see the following output where some of the pods are still in the ContainerCreating phase. After some time you will see all the pods are in a Running state.


NAME           READY  STATUS       RESTARTS  AGE

nginx-776567f984-4vrmn  0/1   ContainerCreating  0     3s

nginx-776567f984-5556g  1/1   Running       0     3s

nginx-776567f984-8z8mj  0/1   ContainerCreating  0     3s

nginx-776567f984-9s2jb  1/1   Running       0     3m45s

nginx-776567f984-9sbdd  0/1   ContainerCreating  0     3s

nginx-776567f984-dnp6s  0/1   ContainerCreating  0     3s

nginx-776567f984-p9qf8  0/1   ContainerCreating  0     3s

nginx-776567f984-sdrns  1/1   Running       0     3m45s

nginx-776567f984-vplg9  0/1   ContainerCreating  0     3s

nginx-776567f984-vxdzw  1/1   Running       0     3m45s

Enter fullscreen mode Exit fullscreen mode

If you want to scale down the application replicas, say from 10 to 2, you can do this by running the following command:


kubectl scale deployments nginx --replicas=2

Enter fullscreen mode Exit fullscreen mode

Verify it using kubectl get pods -l app=frontend. Some of the pods will be in the Terminating state.


NAME           READY  STATUS    RESTARTS  AGE

nginx-776567f984-4vrmn  1/1   Terminating  0     112s

nginx-776567f984-5556g  1/1   Terminating  0     112s

nginx-776567f984-8z8mj  1/1   Terminating  0     112s

nginx-776567f984-dnp6s  0/1   Terminating  0     112s

nginx-776567f984-p9qf8  1/1   Terminating  0     112s

nginx-776567f984-sdrns  1/1   Running    0     5m34s

nginx-776567f984-vxdzw  1/1   Running    0     5m34s

Enter fullscreen mode Exit fullscreen mode

Top comments (0)