k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/images/resource-consumer/README.md (about)

     1  # Resource Consumer
     2  
     3  ## Overview
     4  Resource Consumer is a tool which allows to generate cpu/memory utilization in a container.
     5  The reason why it was created is testing kubernetes autoscaling.
     6  Resource 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
    12  Resource Consumer starts an HTTP server and handle sent requests.
    13  It listens on port given as a flag (default 8080).
    14  Action of consuming resources is send to the container by a POST http request.
    15  Each http request creates new process.
    16  Http request handler is in file resource_consumer_handler.go
    17  
    18  The 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  
    28  Consumes specified amount of millicores for durationSec seconds.
    29  Consume CPU uses "./consume-cpu/consume-cpu" binary (file consume-cpu/consume_cpu.go).
    30  When CPU consumption is too low this binary uses cpu by calculating math.sqrt(0) 10^7 times
    31  and if consumption is too high binary sleeps for 10 millisecond.
    32  One 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  
    38  Consumes specified amount of megabytes for durationSec seconds.
    39  Consume Memory uses stress tool (stress -m 1 --vm-bytes megabytes --vm-hang 0 -t durationSec).
    40  Request 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  
    46  Bumps metric with given name by delta for durationSec seconds.
    47  Custom metrics in Prometheus format are exposed on "/metrics" endpoint.
    48  
    49  ### CURL example
    50  ```console
    51  kubectl 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'
    52  kubectl get services resource-consumer
    53  ```
    54  
    55  There 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
    58  curl --data "millicores=300&durationSec=600" http://<EXTERNAL-IP>:8080/ConsumeCPU
    59  ```
    60  
    61  300 millicores will be consumed for 600 seconds.
    62  
    63  ## Image
    64  
    65  Docker 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
    70  1. Consume more resources on each node that is specified for autoscaler
    71  2. Observe that cluster size increased
    72  
    73  ### Horizontal autoscaling of pod
    74  1. Create consuming RC and start consuming appropriate amount of resources
    75  2. Observe that RC has been resized
    76  3. Observe that usage on each replica decreased
    77  
    78  ### Vertical autoscaling of pod
    79  1. Create consuming pod and start consuming appropriate amount of resources
    80  2. Observed that limits has been increased