DEV Community

Jeremy Herzog
Jeremy Herzog

Posted on

Running Cicada Distributed Tests in Kubernetes

Cicada Distributed’s scalability and flexibility comes from being able to run a containerized testing workload. In the initial version of Cicada Distributed, this was only available in Docker. Cicada Distributed 1.2.0 introduces Kubernetes support to run those same workloads in a K8s cluster. In this tutorial, you’ll set up a local K8s cluster using k3d, (a lightweight version of Kubernetes that runs in Docker containers), modify the Cicada Distributed cluster for local usage with Kustomize, and use that to host the tests.

This guide is also available on the Cicada Distributed docsite.

Setting up the cluster

Begin by installing k3d and ensuring that Kustomize is installed and available to use with kubectl -k. Once this is installed, start the k3d cluster:

k3d cluster create -p "8283:30083@server[0]" -p "8284:30084@server[0]"
Enter fullscreen mode Exit fullscreen mode

This will create a cluster with two node ports exposed on localhost:8283 and localhost:8284. Because these ports map to 30083 and 30084 respectively in the cluster, we’ll also have to modify the install of Cicada using Kustomize.

First, create a directory for the overlay and get the installation YAML into a file:

mkdir cicada-distributed-overlay
cicada-distributed start-cluster --mode=KUBE > cicada-distributed-overlay/cicada.yaml
Enter fullscreen mode Exit fullscreen mode

Next, create a file called cicada-distributed-overlay/patch.yaml and add this to the contents:

apiVersion: v1
kind: Service
metadata:
  name: cicada-distributed-datastore-client
spec:
  ports:
  - port: 8283
    protocol: TCP
    targetPort: 8283
    nodePort: 30083
  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  name: cicada-distributed-container-service
spec:
  ports:
  - port: 8284
    protocol: TCP
    targetPort: 8284
    nodePort: 30084
  type: NodePort
Enter fullscreen mode Exit fullscreen mode

This will override the datastore-client and container-service services to use a NodePort bound to 30083 and 30084 in the cluster, so we can access them locally.

Next, you’ll need to merge the files using Kustomize. To do this, add a file called cicada-distributed-overlay/kustomization.yaml:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - cicada.yaml
patchesStrategicMerge:
  - patch.yaml
Enter fullscreen mode Exit fullscreen mode

Next, apply the directory by using the -k flag in kubectl:

kubectl apply -k cicada-distributed-overlay
Enter fullscreen mode Exit fullscreen mode

This will create all the resources and modify the services for usage in k3d.

Getting an API into K8s

In a previous article, a simple REST API was developed to demonstrate Cicada Distributed. The source code for that API is available here. For this example, you’ll need to add the API image to the k3d cluster and start it using the provided Kube YAML.

The demo app can be cloned from cicadatesting/cicada-distributed-demos:

git clone https://github.com/cicadatesting/cicada-distributed-demos.git
Enter fullscreen mode Exit fullscreen mode

First, build the API and database and add the images to the cluster:

cicada-distributed-demos/rest-api/app :
docker build -t cicadatesting/demo-api-app:local .
docker build -t cicadatesting/demo-api-flyway:local -f flyway.dockerfile .
k3d image import cicadatesting/demo-api-app:local
k3d image import cicadatesting/demo-api-flyway:local
Enter fullscreen mode Exit fullscreen mode

Next, install the app with the code in kube-app.yaml:

kubectl apply -f kube-app.yaml
Enter fullscreen mode Exit fullscreen mode

This should start the API, database, and a job to install the database schema.

Running the tests

Once an example app is running, we can run Cicada tests against it. Navigate to the cicada-distributed-demos/rest-api/integration-tests. Since it is running in k3d, the image needs to be imported into the cluster. To build, run:

docker build -t cicadatesting/cicada-distributed-demo-integration-test:local .
Enter fullscreen mode Exit fullscreen mode

Next, import the image with:

k3d image import cicadatesting/cicada-distributed-demo-integration-test:local
Enter fullscreen mode Exit fullscreen mode

Finally, start the test by running:

cicada-distributed run --mode=KUBE --image=cicadatesting/cicada-distributed-demo-integration-test:local
Enter fullscreen mode Exit fullscreen mode

You should see the test spin up and execute the 4 test scenarios.

(Originally posted on Medium)

Top comments (0)