How to Use Kubectl Scale Deployment in Kubernetes

Importantly, scaling changes happen automatically in either direction: You don’t need to tell kubectl scale to “scale up” or “scale down.” Kubernetes always applies the correct actions to achieve the new desired state. You just declare the number of replicas that you want to have running.

3. Preventing unexpected scaling changes

kubectl scale can have safety implications because the command immediately applies the requested scaling change. This could lead to earlier changes being overwritten during incidents and other fast-paced scenarios.

For instance, imagine if one engineer tries to scale up to five replicas, believing there are currently three replicas running, but another developer has already scaled up to six replicas. 

In this case, running kubectl scale --replicas 5 will actually remove one of the new replicas, unbeknownst to the first engineer.

kubectl scale allows you to prevent this problem by including the --current-replicas flag with your commands. When this flag is present, the scaling change will only proceed if the number of existing replicas matches --current-replicas:

Read more here: Source link