Prerequisite...you MUST have a running installation of Docker!
For this experiment, we will:
- install a local Kubernetes cluster running in Docker
- optionally install some tooling to give us visibility into the cluster
- build a custom
k6
binary having xk6-kubernetes - run some simple scripts to test our local cluster
To run our Kubernetes cluster, we'll use the k3d project. Follow the instructions there for installation.
I personally used Homebrew to install, i.e.
brew install k3d
Once installed, we'll create our cluster using the following command:
k3d cluster create local-kube-cluster \
--api-port 6550 \
-p "8081:80@loadbalancer" \
--agents 3 \
--k3s-arg '--kube-apiserver-arg=feature-gates=EphemeralContainers=true@server:*'
After this command completes, you will have a local Kubernetes cluster running, having multiple nodes...just like a real cluster.
You can setup some tools to make life easier and provide visibility into the cluster. For me, a light-weight option is the k9s utility. This provides a text-based user interface from the command-line for the Kube cluster. Other options exist, like Lens, Octant, among others I'm sure.
For myself once again, I used Homebrew, i.e.
brew install derailed/k9s/k9s
.
In order to create k6 test scripts which incorporate the ability to interact with Kubernetes resources, we'll need to compile and extended version of k6]
using xk6.
Prerequisite: You will need to have a Go(lang) development environment setup locally to compile the extended version!
# Install xk6 into your local toolset
go install go.k6.io/xk6/cmd/xk6@latest
# Build an new k6 binary with k8s support
# (command provided by the "bundle builder" at https://k6.io/docs/extensions/bundle-builder/)
xk6 build v0.38.3 --with github.com/grafana/xk6-kubernetes
Now you should be set to use the Kubernetes client within your test scripts! k8s-playground.js can get you started!
Hi @javaducky (Paul),
We are testing GRPC call using k6 . For that we need to port-forward a particular service before we can call GRPC method.(Currently we are doing it manually.)
Is port-forwarding is yet not available in xk6 Kubernetes?
Are you guys planning to introduce this capability any time sooner ? :)
Thanks in advance.
Regards,
SaifAli Sanadi