#037 Kubernetes - Scaling up & down
Tags: kubernetes, devops, tutorial
Published: 2020-07-19 21:04:52

# 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](https://media1.tenor.com/images/bc57d776582f27c3f44e018b9338eac8/tenor.gif?itemid=4865991)

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](https://github.com/OmarElKhatibCS/DevOpsJourney/tree/master/app_037)
***
# Imperative scale
We have 2 methods to scale imperative and declarative (explained what is difference before [here](https://dev.to/elkhatibomar/031-kubernetes-pods-lab-1-55nf)).

![replicas_pods](https://dev-to-uploads.s3.amazonaws.com/i/gic7ibdsbo6e8mbmzm9n.png)

```bash
kubectl get replicasets
kubectl get pods
```
I have 1 replica and 4 pods created by this replica.
let's try to scale it:
- imperative (not recommended) : 
![scale_up_imp](https://dev-to-uploads.s3.amazonaws.com/i/41kzbo4lyh1azdk0g1qf.png)
```bash
kubectl scale --replicas=6 replicaset myapp-replicaset
```
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](https://dev-to-uploads.s3.amazonaws.com/i/1njyt7httivtj8gdwyff.png)
as soon when we press enter , we can see 2 new pods are creating.

![get_pods_2](https://dev-to-uploads.s3.amazonaws.com/i/s184fz0x6vd8uxariwdn.png)
after few seconds , we see they are now 6 up and running :D

now time to scale down 
![scale_down](https://dev-to-uploads.s3.amazonaws.com/i/vmqpdc9jigfe8z676gad.png)
```bash
kubectl scale --replicas=2 replicaset myapp-replicaset
```
just we decrease the number to 2
![terminating](https://dev-to-uploads.s3.amazonaws.com/i/ji1ij7fpbt3vxf8nz22j.png)
We can see that 4 of our pods are terminating.
![dead](https://dev-to-uploads.s3.amazonaws.com/i/enmauje1ljbcv0i4vq5j.png)
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](https://dev-to-uploads.s3.amazonaws.com/i/ao9gfne38xzfplnyba86.png)
All what I do is change the replicas number to 6.

![dec](https://dev-to-uploads.s3.amazonaws.com/i/6qud69j3m8hxfva0wpiy.png)
```bash
kubectl replace -f app_037_declarative_scale_up.yml
```
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](https://dev-to-uploads.s3.amazonaws.com/i/cqob2sis69u4b88rp6b4.png)
We can see 6 pods are now creating.
![done](https://dev-to-uploads.s3.amazonaws.com/i/9y2y3p9891dqjyo5b7z2.png)
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](https://media.tenor.com/images/088801b49766dc5da22bea802cf58c78/tenor.gif)
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.