Install testing module as a StatefulSet
Introduction
You can install the Akto testing module in your Kubernetes cluster using the akto-stateful-mini-testing Helm chart. It runs the testing module as a Kubernetes StatefulSet and connects it to a Kafka broker that uses SASL authentication.
Use this chart when you want a testing pod that keeps a stable name and can continue a running test after a restart.
How it works
A regular Kubernetes Deployment gives pods random names, and a replacement pod starts with no history. This chart works differently:
Stable pod names: pods are named
akto-external-testing-0,akto-external-testing-1, and so on. A pod keeps the same name when it restarts or moves to another node.One storage volume per pod: each testing pod saves the state of its current test run in the
/app/testing-infofolder. The chart creates a separate PersistentVolumeClaim (PVC) for every pod, 100Mi by default. Pods never share a volume.Kafka runs separately: the queue of test messages and the progress of each run are kept in a Kafka broker that runs outside the testing pod. The testing pod connects to it using SASL.
Restarts are safe: when a pod restarts, it re-attaches to its own volume, reconnects to Kafka, and continues the run where it stopped instead of starting over.
Scaling up: each extra pod gets its own new volume.
Scaling down or uninstalling: volumes are not deleted automatically, so nothing is lost by accident. See Uninstall to remove them.
Prerequisites
A Kubernetes cluster where you have permission to deploy.
Helm installed.
A default storage class in your cluster that can create volumes. Most managed clusters (EKS, GKE, AKS) already have one. You can check with
kubectl get storageclass.A Kafka broker with SASL enabled that the testing pod can reach. You need its address, the SASL mechanism (
PLAIN,SCRAM-SHA-256orSCRAM-SHA-512), and a SASL username and password. If you do not have a Kafka broker yet, see Set up Kafka and do that first.The Database Abstractor service is reachable from the cluster. You will pass its URL during install.
Your Database Abstractor Token:
Log in to the Akto dashboard at app.akto.io.
Go to Quick Start > Hybrid Saas and click Connect.
Copy the JWT token. It is also called the
Database Abstractor Token.
Step 1: Install the testing module
Add the Akto Helm repository.
If you have already added it, update it instead:
Create a secret with your Kafka username and password.
Install the chart. Use your Kafka broker address and the secret from the previous step.
Check that it is running.
You should see:
a pod named
akto-external-testing-0in theRunningstate, anda PVC named
testing-info-akto-external-testing-0in theBoundstate.
Database Abstractor Token
By default, the token is passed directly with --set ...databaseAbstractorToken=<token>, as in the install command above. You can store it in a Kubernetes secret instead. Pick one option and add its flags to the helm install command.
Use a secret you created. The secret needs the key token.
--set testing.aktoApiSecurityTesting.env.useSecretsForDatabaseAbstractorToken=true --set testing.aktoApiSecurityTesting.env.databaseAbstractorTokenSecrets.existingSecret=<secret-name>
Pass the token directly
--set testing.aktoApiSecurityTesting.env.databaseAbstractorToken=<token>
To create your own secret:
Kafka credentials
The testing module reads the Kafka username and password from a secret or from values you pass directly. Pick one and add its flags to the helm install command.
Use a secret you created. The secret needs the keys username and password.
--set testing.kafka1.env.useSecretsForSaslCredentials=true --set testing.kafka1.env.saslCredentialsSecrets.existingSecret=<secret-name>
Pass the values directly
--set testing.kafka1.env.saslUsername=<username> --set testing.kafka1.env.saslPassword=<password>
The default SASL mechanism is SCRAM-SHA-512. To use another one, set testing.kafka1.env.saslMechanism to PLAIN or SCRAM-SHA-256. If your Kafka does not use SASL, set testing.kafka1.useSasl=false.
Options
Add these flags to the helm install command as needed.
Set the Database Abstractor service URL
--set testing.aktoApiSecurityTesting.env.databaseAbstractorUrl="<database-abstractor-service-url>"
Run more than one testing pod
--set testing.replicas=<count>
Run multiple tests in parallel
--set testing.aktoApiSecurityTesting.env.concurrentTesting=true
Use a specific storage class
--set testing.persistence.storageClass=<storage-class>
Change the volume size (default 100Mi)
--set testing.persistence.size=<size>
Use a proxy
--set tokens.env.proxyUri="<proxy-uri>" --set tokens.env.noProxy="<no-proxy-urls>"
For example, to run 3 pods that run tests in parallel:
This creates pods akto-external-testing-0, -1 and -2, each with its own volume.
Uninstall
Remove the testing module.
The volumes are kept after uninstall. If you no longer need the data, delete them too.
If you created Kafka with the example in Set up Kafka, remove it with kubectl delete -f kafka-sasl.yaml.
Set up Kafka (if you do not have one)
If your organization already runs a Kafka broker with SASL, skip this section and use it in Step 1. Otherwise, set one up before you install the testing module. The testing module needs a Kafka broker that it can reach from inside the cluster, and you need:
the broker address, for example
kafka-sasl.<your-namespace>.svc.cluster.local:9092the SASL mechanism:
PLAIN,SCRAM-SHA-256orSCRAM-SHA-512a SASL username and password
If you do not have a Kafka broker yet, you can use the example below. It starts a single broker with SCRAM-SHA-512 authentication. It does not use a persistent volume, so use it for trying things out, or add a volume for /var/lib/kafka/data for long-term use.
Create a secret with the Kafka username and password. The testing module will use the same secret, so skip this if you already created
kafka-sasl-credentials.
Save the following as
kafka-sasl.yaml, replace<your-namespace>, and apply it withkubectl apply -f kafka-sasl.yaml.
Check that Kafka is running.
The broker address is now kafka-sasl.<your-namespace>.svc.cluster.local:9092. Use it as kafkaBrokerUrl in Step 1.
Troubleshooting
Pod stays Pending
Run kubectl describe pvc -n <your-namespace>. The cluster likely has no default storage class. Set one with testing.persistence.storageClass.
Pod cannot connect to Kafka
Check kafkaBrokerUrl and that the pod can reach the broker. Look for connection errors in the logs: kubectl logs <pod-name> -c akto-api-security-testing -n <your-namespace>.
Kafka authentication fails
Check that the username, password and mechanism match what the broker expects. A message like SaslAuthenticationException in the logs means the credentials or mechanism are wrong.
Pod fails with CreateContainerConfigError
The secret named in existingSecret does not exist in the namespace, or it is missing a key. The Kafka secret needs username and password. The token secret needs token.
Run stays at 0% after a restart
Kafka lost its data. Use a Kafka that stores its data on a persistent volume.
Pod cannot reach the Database Abstractor service
Make sure the Database Abstractor service is reachable from the cluster. If you use a proxy, set tokens.env.proxyUri.
Need help?
Contact us at help@akto.io or on Discord.
Last updated