...

Text file src/k8s.io/kubernetes/test/images/resource-consumer/README.md

Documentation: k8s.io/kubernetes/test/images/resource-consumer

     1# Resource Consumer
     2
     3## Overview
     4Resource Consumer is a tool which allows to generate cpu/memory utilization in a container.
     5The reason why it was created is testing kubernetes autoscaling.
     6Resource Consumer can help with autoscaling tests for:
     7- cluster size autoscaling,
     8- horizontal autoscaling of pod - changing the size of replication controller,
     9- vertical autoscaling of pod - changing its resource limits.
    10
    11## Usage
    12Resource Consumer starts an HTTP server and handle sent requests.
    13It listens on port given as a flag (default 8080).
    14Action of consuming resources is send to the container by a POST http request.
    15Each http request creates new process.
    16Http request handler is in file resource_consumer_handler.go
    17
    18The container consumes specified amount of resources:
    19
    20- CPU in millicores,
    21- Memory in megabytes,
    22- Fake custom metrics.
    23
    24### Consume CPU http request
    25- suffix "ConsumeCPU",
    26- parameters "millicores" and "durationSec".
    27
    28Consumes specified amount of millicores for durationSec seconds.
    29Consume CPU uses "./consume-cpu/consume-cpu" binary (file consume-cpu/consume_cpu.go).
    30When CPU consumption is too low this binary uses cpu by calculating math.sqrt(0) 10^7 times
    31and if consumption is too high binary sleeps for 10 millisecond.
    32One replica of Resource Consumer cannot consume more that 1 cpu.
    33
    34### Consume Memory http request
    35- suffix "ConsumeMem",
    36- parameters "megabytes" and "durationSec".
    37
    38Consumes specified amount of megabytes for durationSec seconds.
    39Consume Memory uses stress tool (stress -m 1 --vm-bytes megabytes --vm-hang 0 -t durationSec).
    40Request leading to consuming more memory then container limit will be ignored.
    41
    42### Bump value of a fake custom metric
    43- suffix "BumpMetric",
    44- parameters "metric", "delta" and "durationSec".
    45
    46Bumps metric with given name by delta for durationSec seconds.
    47Custom metrics in Prometheus format are exposed on "/metrics" endpoint.
    48
    49### CURL example
    50```console
    51kubectl run resource-consumer --image=gcr.io/k8s-staging-e2e-test-images/resource-consumer:1.9 --expose --service-overrides='{ "spec": { "type": "LoadBalancer" } }' --port 8080 --requests='cpu=500m,memory=256Mi'
    52kubectl get services resource-consumer
    53```
    54
    55There are two IPs.  The first one is internal, while the second one is the external load-balanced IP.  Both serve port 8080. (Use second one)
    56
    57```console
    58curl --data "millicores=300&durationSec=600" http://<EXTERNAL-IP>:8080/ConsumeCPU
    59```
    60
    61300 millicores will be consumed for 600 seconds.
    62
    63## Image
    64
    65Docker image of Resource Consumer can be found in Google Container Registry as gcr.io/k8s-staging-e2e-test-images/resource-consumer:1.9
    66
    67## Use cases
    68
    69### Cluster size autoscaling
    701. Consume more resources on each node that is specified for autoscaler
    712. Observe that cluster size increased
    72
    73### Horizontal autoscaling of pod
    741. Create consuming RC and start consuming appropriate amount of resources
    752. Observe that RC has been resized
    763. Observe that usage on each replica decreased
    77
    78### Vertical autoscaling of pod
    791. Create consuming pod and start consuming appropriate amount of resources
    802. Observed that limits has been increased

View as plain text