Course contentsShow
← Cloud and Infrastructure
Lesson 1174 of 2,98923. Kubernetes WorkloadsFree lesson

Scaling Deployments

Scale Deployments manually using kubectl scale or by updating spec.replicas in the manifest.

Scaling Deployments

What you'll learn: How to manually increase or decrease the number of Pod replicas in your Deployment using kubectl or YAML manifests.

Why Scale?

Scaling is the process of adjusting how many identical Pod replicas your application runs. Think of it like adding or removing checkout lanes at a grocery store—more lanes handle more customers, fewer lanes save resources when it's quiet.

Manual Scaling Methods

You have two primary ways to scale a Deployment:

Method 1: Using kubectl scale

The fastest way is the kubectl scale command:

kubectl scale deployment my-app --replicas=5

This immediately adjusts your Deployment to run exactly 5 Pod replicas. You can scale up (increase replicas) or scale down (decrease replicas) depending on your needs.

Method 2: Updating the Manifest

Edit your Deployment's YAML file and modify the spec.replicas field:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 5  # Changed from 3 to 5
  selector:
    matchLabels:
      app: my-app
  template:
    # ... pod template

Then apply the changes:

kubectl apply -f deployment.yaml

What Happens When You Scale?

Kubernetes' ReplicaSet controller (managed by your Deployment) immediately detects the desired replica count has changed. It creates new Pods if scaling up, or gracefully terminates excess Pods if scaling down, always working toward your specified number.

Key Takeaway: Scaling Deployments is straightforward—use kubectl scale for quick adjustments or update spec.replicas in your manifest for declarative, version-controlled scaling. Kubernetes handles the Pod creation and deletion automatically to match your desired state.