One of the most important features of Kubernetes is the ability to easily scale our containerized applications. This allows administrators to deal with increased traffic by adding more replicas that can handle the uptick in activity. Kubernetes can handle the load intelligently by distributing the work evenly to pods in the cluster, ensuring that none of them become overwhelmed.
Having multiple replicas also means that we are able to perform rolling updates without any downtime, as replicas can be updated one by one and there will always be enough available to servce the incoming traffic. In this tutorial, we will show you how to use the kubectl scale command to scale applications by configuring additional replicas on a Linux system. Check out some of the example kubectl commands below to get started.
In this tutorial you will learn:
How to scale a deployment up or down in Kubernetes
How to get information on deployment replicas and pods
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
Use Scale Command in Kubernetes
These steps assume that you already have your Kubernetes cluster up and running, and have access to the kubectl command.
Let’s start by checking our currently deployments. In this example, we have a single Nginx container running:
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-server 1/1 1 1 55s
NAME shows the name of our deployment(s). READY is the number of replicas available for the deployment, out of the total. UP-TO-DATE is how many replicas match the latest version of the deployment. AVAILABLE is the number of replicas that have been yet been updated. AGE is how long the deployment has been up since it was created.
Using the scale argument with kubectl, we can scale our deployments up or down and specify the number of replicas we wish for the deployment to use. In this example, we will scale up our nginx-server deployment by taking it from one replica up to five.
In the screenshot above, you can see that we execute the following command immediately after our scale command:
$ kubectl get deployments
At first, the command returns output that indicates 1/5 replicas are ready. A few moments later, when we execute the command again, we confirm that all five of our replicas are now ready.
Let’s get some more information from our replicas by executing:
In this tutorial, we saw how to use the kubectl scale command in Kubernetes on a Linux system. This command is used to increase or decrease the number of replicas that are running for a deployment in our Kubernetes cluster. By controlling the number of replicas, we can scale an application to meet increased demand, or scale it down when the number of replicas becomes excessive. By having multiple replicas, we also have the ability to perform rolling updates.