Table of Contents
URL: https://www.progressiverobot.com/improve-system-performance-with-effective-load-testing-using-k-bench/
Overview
Load Testing is a non-functional software testing process in which the performance of a system is tested under a specific expected load. It determines how the system behaves while being put under load. The goal of Load Testing is to improve performance bottlenecks and to ensure stability and smooth functioning of the system. Load testing gives confidence in the system & its reliability and performance.
K-bench is a framework to benchmark a Kubernetes infrastructure's control and data plane aspects. K-Bench provides a configurable way to prescriptively create and manipulate Kubernetes resources at scale and eventually provide the target infrastructure's relevant control plane and data plane performance metrics.
K-bench allows users to control the client-side concurrency, the operations, and how these different types of operations are executed sequentially or in parallel. In particular, the user can define, through a config file, a workflow of operations for supported resources.
After a successful run, the benchmark reports metrics (e.g., number of requests, API invoke latency, throughput, etc.) for the executed operations on various resource types.
In this tutorial, you will configure the K-bench. This tool needs to be installed on a droplet, preferably with access to the target cluster for testing. You will be configuring (if not already present) a Prometheus stack for your cluster to observe the results of a test run.
K-bench Architecture Diagram
Table of Contents
- [Overview](#overview)
- [K-bench Architecture Diagram](#kbench-architecture-diagram)
- [Prerequisites](#prerequisites)
- [Creating a DO droplet for K-bench](#creating-a-DO-droplet-for-K-bench)
- [K-bench Benchmark Results Sample](#k-bench-benchmark-results-sample)
- [Grafana metric visualization](#grafana-metric-visualization)
- [Grafana API Server Dashboard sample](#grafana-api-server-dashboard-sample)
- [Grafana Node Dashboard sample](#grafana-node-dashboard-sample)
- [Grafana Pod Count sample](#grafana-pod-count-sample)
Prerequisites
To complete this tutorial, you will need:
- DOKS cluster, refer to: Kubernetes-Starter-Kit-Developers if one needs to be created
- Prometheus stack installed on the cluster, refer to: How to Install the Prometheus Monitoring Stack if it's not installed
- A droplet which will serve as the K-bench
master
Creating a DO droplet for K-bench
In this section, you will create a droplet that will serve as your K-bench master. On this droplet, you will clone the K-bench repo, perform the installation, run tests, and/or add any new tests that will fit your use case. The reason for using a droplet is that it is best to have a decoupled resource apart from the cluster, which we can use for just one specific reason, and that is doing load tests and visualizing the results of benchmarks.
Please follow the below steps to create a droplet, install and configure K-bench:
- Navigate to your DO cloud account.
- From the Dashboard, click on the
Createbutton and select theDropletsoption. - Choose the Ubuntu distribution, the basic plan, Regular with SSD CPU options, a region and as
Authenticaionchoose the SSH keys option. If no SSH keys are present Home – IT Consulting & Software Development explains how to create one and add it to the DO account. - From the droplet dashboard, click on the
Consolebutton. After this you will be presented with a screen informing you toUpdate Droplet Console, follow those steps to gain SSH access to the droplet. - Once the SSH access is available, click on the
Consolebutton again. You will be logged in as root into the droplet. - Clone the K-bench repository via HTTPS using this command:
git clone https://github.com/vmware-tanzu/k-bench.git
- Navigate to the cloned repository directory.
cd k-bench/
- Run the install script to install
GOand any other dependenciesK-Benchhas.
./install.sh
- From the DOKS cluster dashboard, click on the
Download Config Fileand copy the contents of the config file.K-benchneeds that information to connect to the cluster. - Create a kube folder where the kube config will be added, paste the contents copied from Step 9, and save the file.
mkdir ~/.kube
vim ~/.kube/config
- As a validation step, run the test start command, which will create a benchmark for the
defaulttest.
./run.sh
- If the test was successful, the tool will output that it started and it is writing the logs to a folder prefixed with
results_run_<date> - Open the benchmark log and observe the results.
cat results_run_29-Jun-2022-08-06-42-am/default/kbench.log
Note: The tests are added under the config folder of k-bench. To change an existing test, its config.json file needs to be updated. The test is run via the -t flag supplied by k-bench. For example, running the cp_heavy_12client is done via: ./run.sh -t cp_heavy_12client
K-bench Benchmark Results Sample
Grafana Metric Visualization
K-bench tests are very easily observable using Grafana. You can create different dashboards to provide observability and understanding of Prometheus metrics. In this section you will explore some useful metrics for Kubernetes and some Dashboards which can offer insight into what is happening with the DOKS cluster under load.
Note: This section can only be completed if the Prometheus stack was created earlier in Step 2 of the [Prerequisites](#prerequisites) section or is installed on the cluster.
Please follow the below steps:
- Connect to Grafana (using default credentials:
admin/prom-operator) by port forwarding to the local machine.
kubectl --namespace monitoring port-forward svc/kube-prom-stack-grafana 3000:80
- Navigate to
http://localhost:3000/and log in to Grafana. - Import the
Kubernetes System Api Serverby navigating tohttp://localhost:3000/dashboard/import, add the15761ID in the box underImport via grafana.comand add Load - From the upper-mentioned dashboard, you will be able to see the API latency, HTTP requests by code, HTTPS requests by verb, etc. You can use this dashboard to monitor the API under load.
- From the Grafana main page, click on the
Dashboardsmenu and click on the Node Exporter Nodes to open aNoderesource-oriented dashboard. You can use this dashboard to monitor the resources available in your nodes during a test. - You can also use various metrics to count the number of pods that have been created during a test. For example, from the
Explorepage, enter the following in the metrics browser:count(kube_pod_info{namespace="kbench-pod-namespace"}). This will show a graph with the number of pods at any given time.
Grafana API Server Dashboard Sample
Grafana Node Dashboard sample
Grafana Pod Count sample
Conclusion
K-bench provides a configurable way for users to create and manipulate Kubernetes resources at scale and generate relevant performance metrics for the target infrastructure. With K-bench, users can control the client-side concurrency, define operations workflows for supported resources, and obtain detailed benchmark reports for various resource types. By using K-bench, users can gain confidence in the reliability and performance of their system, ultimately leading to a better user experience.