TechyPilots Info
TechyPilots.INFO
Home/Tutorials/Kubernetes/Scaling and Management
Kubernetes Tutorial

Kubernetes Scaling and Management

Learn how to scale and manage Kubernetes applications using replicas, Horizontal Pod Autoscaler, Vertical Pod Autoscaler, node autoscaling, resource management, rolling updates, and operational tools.

Level: Intermediate
Topics: Scaling & Operations

Kubernetes Operations

Scale and Manage Workloads

Manual Scaling

Horizontal Pod Autoscaler

Vertical Pod Autoscaler

Node Autoscaling

Rolling Updates & Rollbacks

Introduction

Why scaling and management matter

Kubernetes helps automate deployment and management of containerized applications. After deploying an application, you need to manage capacity, resource usage, updates, failures, and changing traffic demands.

Scaling allows Kubernetes workloads to increase or decrease capacity. Management tools help operators update applications, inspect workload state, monitor resource usage, and recover from deployment problems.

Kubernetes supports manual and automatic scaling approaches, including horizontal scaling, vertical resource scaling, and node autoscaling depending on the workload and cluster configuration.

Scaling Methods

Different ways to scale Kubernetes

Kubernetes provides multiple approaches for adjusting workload capacity and cluster infrastructure.

01

Manual Scaling

Manually increase or decrease the number of replicas managed by a scalable Kubernetes workload.

Key Topics

  • Deployment replicas
  • StatefulSet scaling
  • kubectl scale
  • Manual capacity control
02

Horizontal Pod Autoscaling

Automatically adjusts the number of workload replicas based on observed metrics and configured targets.

Key Topics

  • CPU utilization
  • Memory utilization
  • Custom metrics
  • Replica scaling
03

Vertical Pod Autoscaling

Adjusts container resource requests and limits based on workload usage and resource recommendations.

Key Topics

  • CPU recommendations
  • Memory recommendations
  • Resource rightsizing
  • VPA policies
04

Node Autoscaling

Adjusts cluster node capacity to help provide infrastructure for workloads that cannot be scheduled on existing nodes.

Key Topics

  • Node provisioning
  • Pending Pods
  • Cluster capacity
  • Infrastructure scaling

Manual Scaling

Control the number of replicas

Many Kubernetes workload resources support scaling. You can manually increase or decrease the number of replicas when you need more or less application capacity.

For example, a Deployment can be scaled using kubectl. Kubernetes then works to create or remove Pods until the desired number of replicas is reached.

Manual Scaling Example

kubectl scale deployment nginx   --replicas=5

kubectl get deployment nginx

Horizontal Scaling

Horizontal Pod Autoscaler

The HorizontalPodAutoscaler automatically adjusts the number of replicas for supported workload resources based on observed metrics and configured targets.

A common example is scaling a Deployment based on average CPU or memory utilization. The HPA can increase replicas when demand rises and reduce replicas when demand falls within its configured limits.

Resource requests are important when using utilization-based scaling because utilization is calculated relative to requested resources.

HPA Example

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler

metadata:
  name: nginx-hpa

spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx

  minReplicas: 2
  maxReplicas: 10

  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 60

Vertical Scaling

Vertical Pod Autoscaler

VerticalPodAutoscaler focuses on adjusting CPU and memory resource requests for workloads according to usage and recommendations.

VPA is implemented separately from the core HorizontalPodAutoscaler and requires installation in a cluster before it can be used.

Depending on its configuration and supported features, VPA can provide recommendations or apply updated resource settings to workloads.

VPA Example

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler

metadata:
  name: nginx-vpa

spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx

  updatePolicy:
    updateMode: "Recreate"

Cluster Capacity

Node autoscaling

Scaling Pods is not always enough. If workloads cannot be scheduled because the cluster does not have sufficient capacity, additional nodes may be required.

Node autoscaling can provision additional nodes when workloads need capacity and consolidate or remove unnecessary capacity when appropriate.

The specific node autoscaling implementation depends on the Kubernetes environment and infrastructure configuration.

Scaling Flow

Traffic Increases
       │
       ▼
Horizontal Pod Autoscaler
       │
       ▼
More Pod Replicas
       │
       ▼
Insufficient Node Capacity?
       │
       ▼
Node Autoscaler
       │
       ▼
Additional Cluster Nodes

Resource Management

CPU and memory requests and limits

Resource requests tell the Kubernetes scheduler how much CPU and memory a container requires. Resource limits define the maximum amount of certain resources that a container can use.

Proper resource configuration improves scheduling decisions and helps autoscaling systems make more meaningful decisions.

Resource Configuration

resources:
  requests:
    cpu: "250m"
    memory: "256Mi"

  limits:
    cpu: "500m"
    memory: "512Mi"

Workload Management

Managing Kubernetes applications

01

Replica Management

Deployments and other workload controllers maintain the desired number of application replicas.

02

Rolling Updates

Deployments can gradually replace older application versions with newer versions.

03

Rollbacks

Kubernetes workload management allows you to inspect and roll back supported Deployment revisions when necessary.

04

Resource Requests

Resource requests help the scheduler determine suitable nodes for Pods.

05

Resource Limits

CPU and memory limits define resource boundaries for containers.

06

Monitoring

Metrics and monitoring help operators understand workload health, utilization, and scaling requirements.

Application Updates

Rolling updates and rollbacks

Kubernetes Deployments support controlled updates to application versions. A rolling update gradually replaces existing Pods with new Pods according to the Deployment strategy.

Deployment history can be inspected and supported revisions can be rolled back if a new application version causes problems.

Deployment Management

# Check rollout status
kubectl rollout status deployment/nginx

# View revision history
kubectl rollout history deployment/nginx

# Roll back
kubectl rollout undo deployment/nginx

kubectl

Useful scaling and management commands

Use kubectl to inspect workloads, adjust replica counts, monitor autoscalers, and manage application rollouts.

kubectl get deployments

Display Deployments in the current namespace.

kubectl scale deployment nginx --replicas=5

Manually scale a Deployment to five replicas.

kubectl get hpa

Display HorizontalPodAutoscaler resources.

kubectl top pods

Display available pod resource metrics.

kubectl rollout status deployment/nginx

Watch the rollout status of a Deployment.

kubectl rollout history deployment/nginx

View Deployment revision history.

kubectl rollout undo deployment/nginx

Roll back a Deployment to a previous revision.

kubectl get nodes

Display Kubernetes cluster nodes.

Learning Roadmap

How to learn Kubernetes scaling

Follow these steps to understand how Kubernetes manages workload capacity and cluster resources.

Step 1

Understand Replicas

Learn how Kubernetes workload controllers maintain the desired number of application instances.

Step 2

Practice Manual Scaling

Scale Deployments and StatefulSets manually to understand how replica counts affect application capacity.

Step 3

Configure Resource Requests

Define CPU and memory requests so Kubernetes can schedule workloads and calculate utilization correctly.

Step 4

Learn Horizontal Autoscaling

Use the HorizontalPodAutoscaler to adjust replica counts based on observed metrics.

Step 5

Explore Vertical Scaling

Understand how VerticalPodAutoscaler can recommend or manage resource requests for workloads.

Step 6

Understand Cluster Capacity

Learn how node autoscaling and cluster capacity management support workloads as demand changes.

Best Practices

Scaling and management best practices

Define Resource Requests

Set realistic CPU and memory requests to help Kubernetes schedule workloads and support utilization-based autoscaling.

Set Scaling Limits

Configure sensible minimum and maximum replica counts to prevent unexpected scaling behavior.

Monitor Metrics

Use resource metrics and application monitoring to understand real workload demand before adjusting scaling policies.

Avoid Scaling Conflicts

When an HPA manages a workload, avoid repeatedly applying conflicting replica values from other automation.

Test Application Updates

Test rollout and rollback procedures so application recovery processes are understood before production incidents.

Plan Cluster Capacity

Ensure node capacity and autoscaling infrastructure can support workloads when replica counts increase.

Next Step

Practice scaling a Kubernetes application

Deploy an application, configure resource requests, manually change replica counts, and experiment with Horizontal Pod Autoscaling to understand how Kubernetes responds to changing workload demand.