Intro TestKube
Gonzalo Izquierdo - SysEleven
About me:
Gonzalo Izquierdo
Software Engineer/SRE- SysEleven
Scope of this talk:
What is TestKube
“TestKube is an open-source, cloud-native testing framework which simplifies the testing of Kubernetes applications. It allows users to store, execute and manage tests as part of a Kubernetes cluster. With Testkube, users can utilize multiple testing platforms, orchestrate tests and perform automated testing.”
Some interesting features of Testkube.
Testkube Integrations
More info at:
TestKube architecture
(krew plugin)
(dashboard)
TestKube storage
SOME “OLD WAY OF TESTING MODES” EXAMPLES
Example of testing, I:
Local machine/laptop (true story)
Example of testing, II:
Example of testing, III:
TestKube
TESTING/FEATURES
How TestKube components are installed?
The simplest way: Helm (customizable values for some features like Minio or similar)
After having all the components running in our cluster, we can interact using:
… We will see many pics of dashboard, but it can be made also with testkube CLI/CRDs :)
How to create/run a simple test (using CLI):
$ testkube create test --name curl-test --type curl/test --test-content-type git-file --git-uri https://github.com/userHere/testkube-demo.git --git-branch main --git-path test/curl/hello-test.json
$ testkube run test curl-test
$ testkube get execution curl-test-1
TestKube CLI
TestKube Dashboard
TestKube functions/components
Example test with K6:
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m30s', target: 10 },
{ duration: '20s', target: 0 },
],
};
export default function () {
const res = http.get('https://httpbin.test.k6.io/');
check(res, { 'status was 200': (r) => r.status == 200 });
sleep(1);
}
sample-test.js
Components as K8s resource. Test (from string):
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
name: testing-curl
namespace: testkube
labels:
executor: curl-executor
test-type: curl-test
spec:
type: curl/test
content:
type: string
data: "{\n \"command\": [\n \"curl\",\n \"https://example.org\",\n \"-H\",\n \"'Accept: application/json'\"\n ],\n \"expected_status\": \"200\"\n}"
Components as K8s resource. Test (from Git):
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
name: k6-demo
namespace: testkube
spec:
type: k6/script
content:
type: git-file
repository:
type: git
uri: https://github.com/user/testing.git
branch: main
path: tests/k6/sample-test.js
Test example on UI:
Triggers on TestKube
Triggers allows us to execute tests when an event happens to certain K8s resources. Examples:
Trigger example on UI:
Triggers as K8s resource:
apiVersion: tests.testkube.io/v1
kind: TestTrigger
metadata:
name: testing-demo
namespace: testkube
spec:
action: run
event: modified
execution: test
resource: deployment
resourceSelector:
name: testkube-demo-blue
namespace: default
testSelector:
name: hello-k8s
namespace: testkube
TestSuites
Testsuites are the feature that allows us to orchestrate multiple tests in a simple way. Example:
“ We need to execute the backend testing first with Postman and just after that, check that frontend works as expected with Cypress tests.”
TestSuites allows:
TestSuites on UI
TestSuite as K8s resource/CLI:
apiVersion: tests.testkube.io/v3
kind: TestSuite
metadata:
name: test-demo
namespace: testkube
spec:
steps:
- execute:
- delay: 0s
test: hello-k8s
- delay: 0s
test: testing-curl
stopOnFailure: false
- execute:
- delay: 10s
stopOnFailure: false
- execute:
- delay: 0s
test: k6-demo
stopOnFailure: false
WebHooks:
TestKube allows to setup webhooks that can be integrated with third party systems if some action is executed, example:
Mainly used for communication/info purposes about testing execution/events.
Sources:
Example CR:
apiVersion: tests.testkube.io/v1
kind: TestSource
metadata:
name: test-demo
namespace: testkube
spec:
repository:
type: git
uri: https://github.com/username/testkube-demo
Status Pages (Pro):
Executors:
“The Testkube Container Executor allows you to run your own container images for executing tests. Testkube orchestrates the Tests using the container image as Kubernetes Jobs.”
kubectl -n testkube describe job 6609[…]
Containers:
6609b5909da8aaa5718b8267:
Image: kubeshop/testkube-postman-executor:1.16.39
Port: <none>
Host Port: <none>
Command:
/bin/runner
{"id":"6609b5909da8aaa5718b8267","testName":"hello-k8s","testNamespace":"testkube","testType":"postman/collection","name":"hello-k8s-17","number":17,"command":["newman"],"args":["run","\u003crunPath\u003e","-e","\u003cenvFile\u003e","--reporters","cli,json","--reporter-json-export","\u003creportFile\u003e"],"content":{"type":"string","data":"{\n \"info\": {\n \"_postman_id\": \"02c90123-318f-4680-8bc2-640adabb45e8\",\n \"name\": \"Testkube Demo\",\n \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\"\n },\n \"item\": [\n {\n \"name\": \"hello-k8s test\",\n \"event\": [\n {\n \"listen\": \"test\",\n \"script\": {\n \"exec\": [\n \"pm.test(\\\"Body matches string\\\", () =\u003e {\",\n \" pm.expect(pm.response.text()).to.contain(\\\"Hello Kubernetes\\\")\",\n \"})\",\n \"\",\n \"pm.test(\\\"Body matches string\\\", () =\u003e {\",\n \" pm.expect(pm.response.status).to.equal(\\\"OK\\\")\",\n \"})\"\n ],\n \"type\": \"text/javascript\"\n }\n }\n ],\n \"request\": {\n \"method\": \"GET\",\n \"header\": [],\n \"url\": {\n \"raw\": \"http://hello-kubernetes-service.default\",\n \"protocol\": \"http\",\n \"host\": [\"hello-kubernetes-service\", \"default\"]\n }\n },\n \"response\": []\n }\n ]\n}\n"},"startTime":"2024-03-31T19:12:16.962984859Z","endTime":"0001-01-01T00:00:00Z","executionResult":{"status":"running"},"labels":{"app.kubernetes.io/instance":"testkube-tests","executor":"postman-executor","test-type":"postman-collection"},"bucketName":"958b2a4a-a2e0-4eca-98c3-606b50318dfb","runningContext":{"type":"user-cli"}}
Executors CRD (Integrated Postman)
apiVersion: executor.testkube.io/v1
kind: Executor
metadata:
name: postman-executor
spec:
types:
- postman/collection
executor_type: job
image: kubeshop/testkube-postman-executor:1.16.39
args:
- "run"
- "<runPath>"
- "-e"
- "<envFile>"
- "--reporters"
- "cli,json"
- "--reporter-json-export"
- "<reportFile>"
command:
- "newman"
features:
- artifacts
content_types:
- string
- file-uri
- git-file
- git-dir
- git
meta:
iconURI: postman
docsURI: https://kubeshop.github.io/testkube/test-types/executor-postman
$ kubectl get executor --all-namespaces
NAMESPACE NAME AGE
testkube artillery-executor 11d
testkube curl-executor 11d
testkube cypress-executor 11d
testkube ginkgo-executor 11d
testkube gradle-executor 11d
testkube jmeter-executor 11d
testkube jmeterd-executor 11d
testkube k6-executor 11d
testkube kubepug-executor 11d
testkube maven-executor 11d
testkube playwright-executor 11d
testkube postman-executor 11d
testkube soapui-executor 11d
testkube tracetest-executor 11d
testkube zap-executor 11d
Custom Executors
testkube create executor --name curl-container-executor --executor-type container --image curlimages/curl:7.85.0 --types curl-container/test --command curl
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
name: test-demo-custom-exec
namespace: testkube
spec:
type: curl-container/test
executionRequest:
args:
- https://example.org/
$ testkube run test test-demo-custom-exec
DEMO TIME
Source control for testing files (ArgoCD + TestKube Plugin):
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: testkube-tests
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/lalotone/testkube.git
targetRevision: HEAD
path: tests/postman
plugin:
name: "testkube-v1.0"
destination:
server: https://kubernetes.default.svc
Trigger example with CI/CD: ArgoCD + TestKube
Trigger example with CI/CD (Recap): ArgoCD + TestKube
Source control for testing files:
├── README.md
└── tests
├── k6
│ └── sample-test.js
└── postman
└── hello-k8s.json
Example content for repo:
TestKube Monitoring (Prometheus + Grafana)
Conclusions
Pros:
Cons:
Thanks for your attention :)
Any question?