Skip to main content

Kubernetes HPA Testing with Minikube and K6

This documentation outlines the process of testing Kubernetes Horizontal Pod Autoscalers (HPA) in a Minikube environment. We’ll use stress simulations and the K6 load testing tool to evaluate the scaling behavior of a PHP application.

Prerequisites

  1. Minikube installed and running.
  2. kubectl CLI tool configured for Minikube.
  3. K6 installed for load testing.
  4. Basic knowledge of Kubernetes deployments, services, and HPA.

Setup Steps

1. Deployment Configuration

Create a Kubernetes deployment for the stress-testing PHP application:
Apply the deployment:

2. Service Configuration

Expose the application using a NodePort service:
Apply the service:

3. Horizontal Pod Autoscaler

Configure an HPA to scale pods based on CPU and memory utilization:
Apply the HPA:

Stress Testing the Application

0. Health Check URL

Use the following PHP script to simulate HealthCheck tasks:

1. CPU Stress Test

Use the following PHP script to simulate CPU-intensive tasks:
Place this script in your application directory and access it via the service NodePort.

2. Memory Stress Test

Use the following PHP script to simulate memory-intensive tasks:

3. Load Testing with K6

Use K6 to simulate traffic and trigger the HPA:

Example K6 Script for CPU scaling and memory:

CPU scaling
Memory scaling
Replace <NodeIP> with the Minikube IP address:
Run the K6 test:

Observing HPA Behavior

  1. Monitor the pods:
  2. Check the HPA status:
  3. Check the metrics status:
You should see the HPA scaling pods up and down based on the simulated traffic and resource utilization.
This testing demonstrates how Kubernetes HPA can dynamically scale your application to handle fluctuating workloads efficiently. Using Minikube and K6 provides a lightweight and effective environment for experimenting with these features.