DEV Community

Cover image for #037 Kubernetes - Scaling up & down
Omar
Omar

Posted on

#037 Kubernetes - Scaling up & down

Introduction

this is part 37 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


Scaling up & down

scale_gif

Scaling is very important because some times we need to scale our replicas , scale here is up or down , let's say the trending calendar has end , and visitors start to drop so we need to scale in this case.


Files for this lab

all the files can be found on the repository of this journey , if you already have it just pull if not clone it.
Files can be found here


Imperative scale

We have 2 methods to scale imperative and declarative (explained what is difference before here).

replicas_pods

kubectl get replicasets
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

I have 1 replica and 4 pods created by this replica.
let's try to scale it:

  • imperative (not recommended) : scale_up_imp
kubectl scale --replicas=6 replicaset myapp-replicaset
Enter fullscreen mode Exit fullscreen mode

we specify here how many we need , we take 6 as an example to scale up (was 4) . And what we need to scale? replicaset and we pass here name.

get_pods
as soon when we press enter , we can see 2 new pods are creating.

get_pods_2
after few seconds , we see they are now 6 up and running :D

now time to scale down
scale_down

kubectl scale --replicas=2 replicaset myapp-replicaset
Enter fullscreen mode Exit fullscreen mode

just we decrease the number to 2
terminating
We can see that 4 of our pods are terminating.
dead
we can see we only have 2 pods running now.


Declarative scale

Declarative is better choice because it save our configurations.
I am going to use the app_037_declarative_scale_up.yml
here a look at it.
dec_file
All what I do is change the replicas number to 6.

dec

kubectl replace -f app_037_declarative_scale_up.yml
Enter fullscreen mode Exit fullscreen mode

we use replace and -f then location of our file , since we are in the same directory so we pass name directly. Also we need to scale now from 2 to 6 so I am going to use the scale up yml.

dec_pods
We can see 6 pods are now creating.
done
after seconds our pods are up and running.

To scale down do the same but replace with to down file(can be be found on github link)


End

sorry
Sorry for not writing daily because this month and half I am very busy , I will continue to do it daily on 09/08/2020.

Top comments (0)