/apache-bench-operator

An Kubernetes operator for running Jobs using the Apache HTTP server benchmarking tool.

Primary LanguageGoApache License 2.0Apache-2.0

Apache Benchmark Operator

An Kubernetes operator for running Jobs using the Apache HTTP server benchmarking tool ab.

Installation

The following steps will install the operator into a Kubernetes cluster. Clone this repository somewhere locally to get started.

NOTE: You will need the cluster-admin or equivalent role on the cluster to perform several of these steps.

Create a namespace as needed for your environment.

kubectl create ns benchmark

Create the RBAC resources for the operator.

kubectl apply -n benchmark -f deploy/service_account.yaml
kubectl apply -n benchmark -f deploy/role.yaml
kubectl apply -n benchmark -f deploy/role_binding.yaml

Create the CRD that is managed by the operator.

kubectl apply -f deploy/crds/httpd.apache.org_apachebenches_crd.yaml

Create the Deployment to run the operator.

kubectl apply -n benchmark -f deploy/operator.yaml

If these steps all complete successfully, the operator Pod should be running in the desired namespace.

kubectl get pods -n benchmark
NAME                                     READY   STATUS    RESTARTS   AGE
apache-bench-operator-58dfcbd5fd-ln6v9   1/1     Running   0          13s

Usage

With the operator running, create a new ApacheBench resource that defines the desired state for the benchmark process.

apiVersion: httpd.apache.org/v1alpha1
kind: ApacheBench
metadata:
  name: example-apache-bench
  labels:
    example: basic
spec:
  url: http://httpd.apache.org/

This example is available in the docs/examples directory.

kubectl apply -n benchmark -f docs/examples/apachebench-basic.yaml
apachebench.httpd.apache.org/example-apache-bench created

View the ApacheBench resources.

kubectl get ab -n benchmark
NAME                   AGE
example-apache-bench   106s

A Job will be created to run the benchmark.

kubectl get jobs -n benchmark
NAME                   COMPLETIONS   DURATION   AGE
example-apache-bench   1/1           2s         2m19s

The Job will create a single Pod and should not take very long to run.

kubectl get pods -n benchmark
NAME                                     READY   STATUS      RESTARTS   AGE
apache-bench-operator-58dfcbd5fd-ln6v9   1/1     Running     0          22m
example-apache-bench-wwx7h               0/1     Completed   0          4m8s

View the logs for the Pod to get the result of the benchmark process.

kubectl logs -n benchmark example-apache-bench-wwx7h
This is ApacheBench, Version 2.3 <$Revision: 1874286 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking httpd.apache.org (be patient).....done


Server Software:        Apache/2.4.18
Server Hostname:        httpd.apache.org
Server Port:            80

Document Path:          /
Document Length:        9696 bytes

Concurrency Level:      1
Time taken for tests:   0.013 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      9969 bytes
HTML transferred:       9696 bytes
Requests per second:    79.33 [#/sec] (mean)
Time per request:       12.605 [ms] (mean)
Time per request:       12.605 [ms] (mean, across all concurrent requests)
Transfer rate:          772.34 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        6    6   0.0      6       6
Processing:     6    6   0.0      6       6
Waiting:        6    6   0.0      6       6
Total:         13   13   0.0     13      13

See the docs/examples directory for advanced usage.

License

The Apache Benchmark Operator is released under the Apache 2.0 license. See the LICENSE file for details.