Skip to content

Kubernetes load testing with curl

Kubernetes load testing with curl is a lightweight method for verifying service availability and basic load balancing behavior within a cluster. It typically involves exposing a local port to a Kubernetes Service and using shell loops to send multiple requests rapidly.^[400-devops__06-Kubernetes__k8s-learning__08-collect__README.md]

Procedure

1. Port Forwarding

To access a service running inside the cluster locally, use kubectl port-forward. This command maps a local port (e.g., 8080) to the service's port (e.g., 80).^[400-devops__06-Kubernetes__k8s-learning__08-collect__README.md]

[kubectl port-forward](<./kubectl-port-forward.md>) service/svc-myapp 8080:80 --address 0.0.0.0

2. Sending Requests

Once the service is accessible, a simple Bash for loop can be used to generate traffic.^[400-devops__06-Kubernetes__k8s-learning__08-collect__README.md]

for i in {1..10}
do
   curl localhost:8000
done

Verification

By observing the output of the loop, one can verify if the load is being distributed across different replicas.^[400-devops__06-Kubernetes__k8s-learning__08-collect__README.md] For example, seeing alternating responses like "Version: v1" and "Version: v2" indicates that requests are hitting different backend Pods.^[400-devops__06-Kubernetes__k8s-learning__08-collect__README.md]

Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>

Sources

^[400-devops__06-Kubernetes__k8s-learning__08-collect__README.md]

  • Kubernetes
  • [[Load balancing]]
  • [[Port forwarding]]