<p>I am learning containers and microservices. This question might be basic. Lets us assume I have a microservice running on a container in my PC. I would like to know what happens during a container scale up and scale down. Please explain with a example</p>

Baala Srinivas K
<p>I will assume from the tone of the question that this is a more design question, And the fact that you have tagged both kubernetes and docker I will assume you are planning to use or are already using this to some extent.</p>

<p>Ok now to the premise of the question, considering you have a microservice or in this case, it is interchangeable with a docker container that is running on your machine or VM. </p>

<p>So now what does it mean to scale the service</p>

<p><strong>In Docker</strong> </p>

<ul>
<li>You have to have multiple container instances running of same images on the said VM</li>
<li>These instances are the same docker images running on multiple assigned ports servicing the same application or web app or static website.</li>
<li>This scaled application or web-app is now scaled to the size scale of 2 and is running on say port 8080 and 8081 serving a simple web-app.</li>
<li>Now to make sure these scaled applications are useful for your use case you will have to add a load balancer on top of these 2 applications which can be done using an Nginx proxy.</li>
<li>For scale down, it will mean you will have to stop one of these container instances running using <code>docker stop id</code> </li>
<li>Thus now you have scaled down to the size scale of 1.</li>
</ul>

<p><strong>In Kubernetes</strong></p>

<ul>
<li>In a kubernetes orchestration environment which indirectly uses docker to do its cool stuff, the load balancing and scaling mechanisms, etc are already handled by the kubernetes itself.</li>
<li>So, in this case, say you have a web app container running in a pod, when you execute a command say `kubectl scale pod_name 2', this will call the Kubernetes API and scale up or instruct the docker below to launch another instance of your docker image.</li>
<li>And since the load balancer is handled by the Kubernetes we will just a simple end-point provisioned for us ( there are some other stuff like services  and load balancer endpoints, but we can skip that for our argument)</li>
<li>And in similar fashion you can scale down the number of instances running in a pod and kubernetes will take of everything else while the active traffic is taken care of.</li>
</ul>
