⎈ k8s knowledge compiler

Running Multiple Instances of Your App [page]deterministic

tutorials

##

* Scale an existing app manually using kubectl.

##

The shell commands in this tutorial use POSIX shell syntax, which is supported by the default shells on most Linux and macOS systems (for example, bash, zsh, or sh). Windows users must use a POSIX-compatible shell such as [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install) or [Git Bash](https://gitforwindows.org/) to run the commands as written. Commands that use `export`, `$()`, and similar constructs are not compatible with PowerShell or the Windows Command Prompt.

## Scaling an application

_You can create from the start a Deployment with multiple instances using the --replicas parameter for the kubectl create deployment command._

Previously we created a [Deployment](/docs/concepts/workloads/controllers/deployment/), and then exposed it publicly via a [Service](/docs/concepts/services-networking/service/). The Deployment created only one Pod for running our application. When traffic increases, we will need to scale the application to keep up with user demand.

If you haven't worked through the earlier sections, start from [Using minikube to create a cluster](/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/).

_Scaling_ is accomplished by changing the number of replicas in a Deployment.

If you are trying this after the [previous section](/docs/tutorials/kubernetes-basics/expose/expose-intro/), then you may have deleted the service you created, or have created a Service of `type: NodePort`. In this section, it is assumed that a service with `type: LoadBalancer` is created for the kubernetes-bootcamp Deployment.

If you have _not_ deleted the Service created in [the previous section](/docs/tutorials/kubernetes-basics/expose/expose-intro), first delete that Service and then run the following command to create a new Service with its `type` set to `LoadBalancer`:

```shell kubectl expose deployment/kubernetes-bootcamp --type="LoadBalancer" --port 8080 ```

## Scaling overview

_Scaling is accomplished by changing the number of replicas in a Deployment._

Scaling out a Deployment will ensure new Pods are created and scheduled to Nodes with available resources. Scaling will increase the number of Pods to the new desired state. Kubernetes also supports [autoscaling](/docs/concepts/workloads/autoscaling/) of Pods, but it is outside of the scope of this tutorial. Scaling to zero is also possible, and it will terminate all Pods of the specified Deployment.

Running multiple instances of an application will require a way to distribute the traffic to all of them. Services have an integrated load-balancer that will distribute network traffic to all Pods of an exposed Deployment. Services will monitor continuously the running Pods using endpoints, to ensure the traffic is sent only to available Pods.

Once you have multiple instances of an application running, you would be able to do Rolling updates without downtime. We'll cover that in the next section of the tutorial. Now, let's go to the terminal and scale our application.

### Scaling a Deployment

To list your Deployments, use the `get deployments` subcommand:

```shell kubectl get deployments ```

The output should be similar to:

``` NAME READY UP-TO-DATE AVAILABLE AGE kubernetes-bootcamp 1/1 1 1 11m ```

We should have 1 Pod. If not, run the command again. This shows:

* _NAME_ lists the names of the Deployments in the cluster. * _READY_ shows the ratio of CURRENT/DESIRED replicas * _UP-TO-DATE_ displays the number of replicas that have been updated to achieve the desired state. * _AVAILABLE_ displays how many replicas of the application are available to your users. * _AGE_ displays the amount of time that the application has been running.

To see the ReplicaSet created by the Deployment, run:

```shell kubectl get rs ```

Notice that the name of the ReplicaSet is always formatted as <nobr>[DEPLO …(trimmed)

Sources

tutorials/kubernetes-basics/scale/scale-intro.md · docRunning Multiple Instances of Your App

Related (8)

part_of {{% heading "objectives" %}}describes conf=1
part_of {{% heading "prerequisites" %}}describes conf=1
part_of Scaling an applicationdescribes conf=1
part_of Scaling overviewdescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Scaling a Deploymentdescribes conf=1
part_of Load Balancingdescribes conf=1
part_of Scale Downdescribes conf=1

← all Docs