A simplified version of the kubernetes resource-consumer that is decoupled from the kubernetes build system and provides additional features.
Resouce Consumer allows one to generate the following type of load inside a container:
- CPU in millicores
- Memory in megabytes
- Fake custom metrics
- Disk files in gigabytes
Resource Consumer can help with testing:
- cluster size autoscaling,
- horizontal autoscaling of pod - changing the size of replication controller,
- vertical autoscaling of pod - changing its resource limits.
- eviction scenarios
- reserved resources
Deploy
kubectl run resource-consumer --image dj80hd/resource-consumer --replicas 2 --expose --port 8080Add Load (more examples below)
kubectl run curl --rm -it --image curlimages/curl --restart Never -- curl --data "megabytes=200&durationSec=300" resource-consumer:8080/consume-memTest
kubectl top pod | grep resource-consumerCleanup
kubectl delete svc,deploy resource-consumer
docker run --name resource-consumer -d -p 8080:8080 dj80hd/resource-consumer- Take up 1/8 CPU for 10 minutes:
curl --data "millicores=125&durationSec=600" http://localhost:8080/consume-cpuNote: One replica of Resource Consumer cannot consume more that 1 cpu.
- Take up 200M Memory for 5 minutes:
curl --data "megabytes=200&durationSec=300" http://localhost:8080/consume-memNote: Request to consume more memory then container limit will be ignored.
- Take up 10G of disk for 10 mintutes:
curl --data "gigabytes=10&durationSec=600&filename=/var/log/foo.log" http://localhost:8080/consume-diskNote: Requests to create files in non-existent directories will be ignored.
- Set metric
footo 1.14 for 5 minutes:
curl --data "metric=foo&delta=1.14&durationSec=300" http://localhost:8080/bump-metricNote: Custom metrics in Prometheus format are exposed on "/metrics" endpoint.
Observe local cpu, mem, and disk:
echo "CPU: $(docker stats --no-stream | grep resource-consumer | awk '{print $3}')" && \
echo "MEM: $(docker stats --no-stream | grep resource-consumer | awk '{print $4,$5,$6}' | tr -d ' ')" && \
echo "DSK: $(docker ps -s | grep resource-consumer | awk '{print $(NF-2),$(NF-1),$NF}')"