Scaling the guestbook frontend component

Kubernetes gives us the ability to scale each component of an application dynamically. In this section, we will show you how to scale the frontend of the guestbook application as follows:

ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kc scale --replicas=6 deployment/frontend
deployment.extensions/frontend scaled
ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kc get all
NAME READY STATUS RESTARTS AGE
pod/frontend-56f7975f44-2rnst 1/1 Running 0 4s
pod/frontend-56f7975f44-4tgkm 1/1 Running 0 4s
pod/frontend-56f7975f44-7sdn5 1/1 Running 0 2h
pod/frontend-56f7975f44-hscn7 1/1 Running 0 2h
pod/frontend-56f7975f44-p2k9w 0/1 ContainerCreating 0 4s
pod/frontend-56f7975f44-pqvbg 1/1 Running 0 2h

We achieve this by using the scale option in kubectl. You can set the number of replicas you want, and Kubernetes takes care of the rest. You can even scale it down to zero (one of the tricks used to reload configuration when the application doesn't support the dynamic reload of configuration). You can see this trick in action as follows:

ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kc scale --replicas=0 deployment/frontend
deployment.extensions/frontend scaled
ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kc get pods
NAME READY STATUS RESTARTS AGE
frontend-56f7975f44-4vh7c 0/1 Terminating 0 3m
frontend-56f7975f44-75trq 0/1 Terminating 0 3m
frontend-56f7975f44-p6ht5 0/1 Terminating 0 3m
frontend-56f7975f44-pqvbg 0/1 Terminating 1 14h

Let's bring it back to 3 replicas from 0 by using the following command:

ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kc scale --replicas=3 deployment/frontend
deployment.extensions/frontend scaled

In this chapter, you have experienced how easy it is to scale pods with Kubernetes. This capability provides a very powerful tool for you to not only dynamically adjust your application components, but also to provide resilient applications with failover capabilities enabled by running multiple instances of components at the same time.

Furthermore, its declarative nature is another key advantage of using Kubernetes. In the previous examples, we saw that we need to define what we want (namely, the number of the replicas) in the .yaml file description, and Kubernetes handles the rest.

Besides the number of replicas, we can define other components in a descriptive way, some of which are given here:

  • Desired versus available nodes (if they are the same, take no action)
  • The number of pods
  • Pod placement based on CPU/memory requirements
  • The handling of special cases such as StatefulSets
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset