Lab 05: Scaling Your Application

Welcome to Lab 05! In this session, we'll learn how to efficiently scale your applications using Kubernetes. We'll explore both declarative and imperative methods to give you the tools and understanding needed to manage your app's scalability like a pro.

Scaling with the Declarative Approach

The declarative approach is about telling Kubernetes what you want your application's infrastructure to look like, without having to detail every step to get there. This method aligns with the Infrastructure as Code (IaC) philosophy, allowing you to manage your infrastructure through version-controlled configuration files. This ensures transparency, reproducibility, and consistency.

How to Scale Up:

Imagine our Node.js application is running smoothly with two replicas, but we need more horsepower to handle increasing load. Here's how we can scale up:

  1. First, make sure you're in the Node.js app directory. If it's not on your machine, grab it from Lab 02.
    cd deploy/nodejsapp
  2. Open the deployment.yaml file and change the replicas value from 2 to 3. Your file should now look something like this:
    apiVersion: apps/v1
    kind: Deployment
      name: nodejs-app
      replicas: 3
          app: nodejs-app
            app: nodejs-app
          - name: nodejs-app
            - containerPort: 80
  3. Apply the changes to scale up your deployment:
    kubectl apply -f deployment.yaml


Scaling with the Imperative Method

The imperative method is more hands-on. You directly command the Kubernetes cluster to change your app's resources in real-time. It's like giving step-by-step instructions without defining the final state ahead of time.

How It Works:

If you're curious to try the imperative method, start by removing the deployment created through the declarative method:

kubectl delete -f deployment.yaml

Next, create a new deployment with three replicas directly:

kubectl create deployment nodejsapp --replicas=3


To scale down in the future, use:

kubectl get deployment
kubectl scale deployment nodejsapp --replicas=2


  • Congratulations! You've mastered scaling your applications up and down using both declarative and imperative methods. Ready for the next challenge? Let's move on to learning how to roll out updates without downtime in the final lab.