Kubernetes Autoscaling

Manual Scaling

Manual HPA

In this lesson, you’ll learn how to manually adjust the replica count of a Kubernetes Deployment to see how pod creation, hostnames, and application behavior change. This manual process lays the groundwork for understanding the Horizontal Pod Autoscaler.

High-Level Architecture

Imagine your Kubernetes cluster as a growing city:

  • Deployments are neighborhoods.
  • Pods are individual houses.
  • Applications run inside those houses, serving end users.

The image is a diagram showing a Kubernetes cluster with a deployment containing pods, and users accessing the pods.

Lab Objectives

In this hands-on lab, you will:

  • Scale a Deployment up and down by changing its replica count.
  • Observe how each pod receives a unique hostname.
  • Understand the effects of replication on application throughput and identity.

The image is a lab overview describing objectives related to scaling a Kubernetes deployment, focusing on hostname changes and the impact of increasing replicas on application output.

Prerequisites

Ensure you have a running Kubernetes cluster and kubectl configured to interact with it.

Demonstrating Manual Scaling

1. Scale the Deployment

Run the following command to increase replicas to three:

kubectl scale deployment flask-web-app --replicas=3

2. Verify the New Pods

List the pods and confirm there are three running instances:

kubectl get pods

Expected output:

NAME                                     READY   STATUS    RESTARTS   AGE
flask-web-app-59d5f5df85-4pvbq           1/1     Running   0          2m12s
flask-web-app-59d5f5df85-f4ktj           1/1     Running   0          111s
flask-web-app-59d5f5df85-sc6jq           1/1     Running   0          2m12s

Each pod now has a unique hostname that changes whenever pods are replaced.

3. Common Commands

CommandDescription
kubectl scale deployment ... --replicasAdjusts the number of pod replicas.
kubectl get podsLists all pods with status and age.

Ephemeral Hostnames

Pods are ephemeral. Their hostnames and IPs can change on restart or rescheduling. For stable network IDs, consider using a StatefulSet.

Key Takeaways

The image presents key takeaways about scaling, hostnames, and application behavior in deployments, highlighting how increasing replicas adds pods, each pod gets a unique hostname, and scaling can affect application behavior.

  • Manually scaling a Deployment is like adding or removing houses in a neighborhood.
  • Each pod gets its own hostname; they’re not preserved across restarts.
  • More replicas boost capacity but can affect apps that rely on host-specific data.
  • For stateful applications, use StatefulSets or external storage to maintain stable identities.

Next Steps

You’ve now seen how manual replica changes work under the hood. Next, we’ll automate this process using the Horizontal Pod Autoscaler to dynamically adjust pod counts based on CPU or memory metrics.

References

Watch Video

Watch video content

Practice Lab

Practice lab

Previous
Why Do We Need to Autoscale