Installing K6 on a Raspberry Pi
2 min read
I’ve recently been doing some performance testing at work using K6 and had the need to test a script locally. I could have run the script on the same machine being load tested, but generally you want to run the test from a different machine so that the test runner itself doesn’t affect the results.
Not having a spare PC available, I turned to my trusty Raspberry PI instead. This makes for a really portable setup that I can just fire up when I need it, and quickly shut it down when I’m done.
Whilst K6 runs perfectly fine on a Raspberry PI, I found the installation process wasn’t exactly as the documentation laid out so I thought I’d write a quick blog post so that I could share with others, and more likely, so I could remember how to do it in the future should I need to do the setup again.
Setup your Raspberry PI
To begin with you’ll need a Raspberry PI v4+ with SD card with Raspberry PI OS installed. I used the PI installer software to preconfigure a login, WI-FI connection and SSH access as I intended to use the PI entirely headlessly.
As with any fresh Raspberry PI installation your first task is to update and upgrade all dependencies.
sudo apt-get update # Update the list of available packages
sudo apt-get upgrade # Upgrade the installed packages
Install K6
So whilst K6 is Raspberry PI compatible, the arm64 distribution is not available via the general installer script, instead we need to download a precompiled binary and install it manually.
To do this, head to the K6 git repos releases page and for the latest release scroll down to the list of assets at the bottom.
From the list, right click the k6-v{VERSION}-linux-arm64.tar.gz
entry and copy the link address.
Now in your Raspberry PI terminal, enter the following commands, replacing {COPIED_URL}
with the URL you just copied, and {VERSION}
with the version number you are downloading.
wget {COPIED_URL}
tar -xvzf k6-v*.tar.gz
cd k6-v{VERSION}-linux-arm64
sudo mv k6 /usr/local/bin/k6
You should now be able to verify that K6 is installed by running the following command:
k6 version
Running a K6 test
To ensure K6 runs without a hitch, create a new test file by running the following command:
sudo nano load_test.js
And then paste in the following contents, followed by CTRL+X
followed by Y
to save the file.
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
http.get('https://test.k6.io');
sleep(1);
}
You should now be able to run the test by calling
k6 run --vus 10 --duration 30s load_test.js
If everything went smoothly, you should get a nice report for the load test.
Wrapping Up
It can be really useful to be able to run load tests locally as it gives you more options for running traces on the solution that might be trickier on externally hosted sites. By using K6 on a Raspberry PI, we have a really nice and simple solution that doesn’t take up much space and can be powered up when needed and then easily stored away when it’s not.
Happy testing 👋