

Table of Contents
Start your free trial.
Start your free trial.
Start your free trial.




Table of Contents
Executive Summary
Local tests give you a green checkmark. Kubernetes gives you a different answer. Network policies block traffic. RBAC denies a service account. A missing ConfigMap stops a pod from starting. None of that shows up in your laptop's test runner.
This guide walks through how to test containers where they actually run, inside a Kubernetes cluster, so the surprises happen in CI and not in production.
What is container testing in Kubernetes?
Container testing in Kubernetes is the practice of running tests against containerized applications inside an actual Kubernetes cluster, where production constraints like network policies, RBAC, resource quotas, and service discovery are enforced. Unlike local unit tests that validate logic in isolation, in-cluster tests verify that containers behave correctly under the same orchestration rules they face in production.
Why it matters: A local environment can mimic Docker, but it cannot replicate admission controllers, custom resource definitions, init containers, pod disruption budgets, or the dozens of other Kubernetes primitives that govern runtime behavior. Testing inside the cluster surfaces the failures that only appear under realistic conditions.
Example: Your API passes health checks locally. After deployment, a missing NetworkPolicy silently blocks ingress, and the service is unreachable. In-cluster tests catch this before users do.
Types of container tests in Kubernetes
Not all tests catch the same problems. A reliable strategy combines several layers, each tuned to a specific failure mode.
A practical sequence in staging looks like this: smoke checks first (about 30 seconds), then integration tests (5 to 10 minutes), then load tests (15 to 30 minutes). The fast tests fail fast and protect cluster resources.
Why test inside Kubernetes instead of locally?
Local unit tests catch syntax errors and broken logic. They cannot catch what happens when admission webhooks, init containers, and pod disruption budgets get involved.
Kubernetes introduces complexity that does not exist locally:
- RBAC policies that block service accounts
- Node affinity rules that leave pods unschedulable
- Security contexts that restrict container capabilities
- Network policies that silently drop traffic between services
- Resource quotas that throttle workloads
- Missing ConfigMaps or Secrets that prevent containers from starting
Testing inside a real cluster validates against the same orchestration engine, admission controllers, and runtime constraints your application faces in production. That catches storage provisioning failures, service mesh misconfigurations, and resource contention scenarios before they turn into 3 AM alerts.
How to run container tests inside Kubernetes
There are three common approaches. The right one depends on whether you're validating a single service, hooking into a deployment lifecycle, or orchestrating tests across teams and clusters.
Option 1: Kubernetes Jobs and custom scripts
Package your test as a container image and run it as a Kubernetes Job. The Job spins up an ephemeral Pod, executes the test, and cleans up.
Use this when you need to run:
- Basic one-off tests like a curl health check
- Simple test automation via scripts or CI/CD pipelines
- Database migrations or batch data processing tests
- Integration tests against real services
- Security scanning as part of a pipeline
Example YAML:
apiVersion: batch/v1
kind: Job
metadata:
name: api-health-check
spec:
template:
spec:
containers:
- name: curl-test
image: curlimages/curl
command: ["curl", "-f", "http://my-service/health"]
restartPolicy: NeverPros:
- Native Kubernetes integration. Tests use the cluster's scheduling, resource quotas, and node affinity.
- Resource isolation. Each test runs in its own Pod with defined CPU and memory limits.
- Parallel execution. Multiple Jobs can run concurrently across nodes.
- Direct access to Services, ConfigMaps, and Secrets without extra wiring.
- RBAC integration through ServiceAccounts.
- Automatic cleanup when Pods terminate.
Cons:
- Logging is available via kubectl logs, but there's no centralized reporting or dashboard unless you build it.
- Retries via backoffLimit are basic. Orchestrating complex flows requires custom scripting.
- Artifact collection is manual.
Option 2: Helm test hooks
Helm test hooks integrate tests into the Helm release lifecycle. They support pre-install, post-install, pre-upgrade, pre-rollback, and pre-delete phases.
Use this when you need to:
- Validate Helm-based deployments after release
- Run compliance or security checks tied to a chart
- Confirm database schema after migrations
- Keep tests coupled to a chart for portability
apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-smoke-test"
annotations:
"helm.sh/hook": test
spec:
containers:
- name: smoke-check
image: curlimages/curl
command: ["curl", "-f", "http://my-service/health"]
restartPolicy: NeverPros:
- Built into your Helm release lifecycle. No extra tooling.
- Chart templating allows environment-specific test configuration.
- GitOps-friendly and declarative.
Cons:
- Test complexity is bounded by what you can stuff into the container.
- Hook weights provide basic ordering, but there's no advanced orchestration, parallelism, or reporting.
- No built-in retry logic or persisted test history.
Option 3: Test orchestration with Testkube
For teams that want coded, scalable, container-native testing, Testkube manages tests as first-class Kubernetes objects.
What Testkube does:
- Defines every test as a Kubernetes Custom Resource
- Runs existing tools (Postman, k6, Cypress, Playwright, custom scripts) inside the cluster
- Triggers tests from CI/CD pipelines, GitOps workflows, schedules, or API calls
- Centralizes logs, results, and artifacts
- Provides a web dashboard for tracking executions across teams
Core concepts:
- TestWorkflows. Custom resources that define how a test runs, what it needs, and what it produces.
- Executors. Containers that know how to run a specific tool (k6, Postman, Cypress, etc.).
- Triggers. Events that start a test: a deployment, a schedule, a GitOps change, an API call.
- Artifacts. Reports and logs collected after each run.
- Agents. Connect distributed clusters back to a central control plane in Platform editions.
Example TestWorkflow running a Postman collection:
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: postman-api-tests
spec:
content:
git:
uri: https://github.com/example/api-tests
paths:
- postman-collection.json
steps:
- name: run-postman-tests
run:
image: postman/newman:6-alpine
args: ["run", "postman-collection.json"]Trigger it from the CLI:
testkube run testworkflow postman-api-testsPros:
- Tests live in the cluster as Kubernetes resources, versioned in Git.
- Supports functional, performance, chaos, and API tests through a single orchestration layer.
- Trigger automation from GitHub Actions, GitOps tools, or APIs.
- Centralizes logs, artifacts, and execution history.
- Scales across multiple clusters with RBAC and team-level controls in Testkube Platform.
Cons:
- Specialized frameworks may require a custom executor.
- Managing tests as Kubernetes resources has a learning curve for teams new to CRDs.
Best practices for container testing in Kubernetes
1. Use isolated namespaces or ephemeral clusters
Run tests in scoped namespaces, or spin up ephemeral clusters with Kind, k3d, or Cluster API. This keeps test data disposable and prevents interference with production workloads.
2. Automate every test through CI/CD
Manual testing does not scale. Integrate container tests into your pipelines so they run on every commit, pull request, or deployment. Faster feedback. Fewer untested changes.
3. Respect security boundaries
Test with the same RBAC roles, service accounts, and network policies you use in production. Misconfigured permissions and missing secrets only surface at runtime if your tests honor the same constraints.
4. Simulate resource constraints
Configure CPU, memory, and ephemeral storage limits that match production. Watch for OOMKilled pods, throttling, and startup failures under tight quotas.
5. Monitor test pods and cluster events
Watch pods and Kubernetes events during execution. Most test failures trace back to scheduling, RBAC, or resource issues that show up there first.
6. Run tests in parallel
Sequential testing wastes cluster capacity. Run tests concurrently to compress feedback cycles and use what the cluster can already give you.
7. Clean up after every run
Delete Jobs, volumes, and Secrets when a test finishes. Leftover resources accumulate fast and quietly drain quotas.
Real-world example: running API tests in Kubernetes with Testkube
Say you have both Postman and k6 API test suites and want them to run inside the cluster after every deployment, not just in CI. Here's how to set that up with Testkube.
Step 1: Install Testkube.
See the installation guide for Helm-based setup.
Step 2: Define k6 and Postman tests as TestWorkflows.
k6 load test:
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: k6-load-test
namespace: testkube
spec:
content:
files:
- path: /data/example.js
content: |-
import http from 'k6/http'
export default function () {
http.get('https://test.k6.io')
}
steps:
- name: run-k6
workingDir: /data
run:
image: grafana/k6:0.49.0
args: ["run", "example.js"]
artifacts:
paths:
- k6-test-report.htmlPostman API test:
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: postman-api-tests
namespace: testkube
spec:
content:
git:
uri: https://github.com/example/api-tests
paths:
- postman-collection.json
steps:
- name: run-postman-tests
run:
image: postman/newman:6-alpine
args: ["run", "postman-collection.json"]
artifacts:
paths:
- newman-report.htmlBoth definitions fetch the test source, execute it inside the cluster, and archive HTML reports as artifacts.
Step 3: Execute the workflows.
#!/bin/bash
testkube workflow run k6-load-test
testkube workflow run postman-api-testsOr trigger execution from the Testkube dashboard.
Step 4: Access logs, artifacts, and execution history.
Testkube collects logs, reports, and artifacts automatically. Execution logs stream in real time through the dashboard or CLI. Test results (Postman HTML, k6 reports) are saved as artifacts. Execution history tracks when each test ran, how long it took, and whether it passed.
Why this matters
Instead of stitching together raw curl scripts or manually deploying k6 pods, Testkube lets you treat tests as first-class Kubernetes objects. CRDs, CLI, and dashboard work together so logs, artifacts, and execution tracking come without glue code.
Testkube Runner Agent vs Testkube Platform
The OSS Runner Agent works for small teams running tests through CLI or pipelines inside a single cluster. Once you span multiple environments or need centralized reporting, the Platform editions add the control plane, dashboard, and multi-cluster management.
Top tools for container testing in Kubernetes
- Testkube. Test orchestration platform for managing and executing tests across containerized environments. CRD-based definitions, dashboards, multi-cluster support.
- k6. Performance testing tool for load and stress testing containerized applications.
- Helm test. Lifecycle testing tied to Helm releases for simple post-deployment validation.
- LitmusChaos. Chaos engineering for resilience and failure scenario testing.
Conclusion
If reliability matters, tests need to live where the application does. Local tests catch the easy stuff. Container-native testing catches the failures that only appear under real cluster conditions.
Combine functional tests with performance and chaos engineering, and you build real confidence in how a system behaves under pressure. Whether the setup is a single Helm chart or a multi-cluster orchestration layer, the principle holds: validate in conditions that resemble production.
FAQs
Can I run Cypress tests in Kubernetes?
Yes. Cypress runs inside a container the same way it runs locally. You package the test suite as a container image, then execute it as a Kubernetes Job, a Helm test hook, or a Testkube TestWorkflow. Running Cypress in-cluster gives you access to internal services without exposing them externally and lets you parallelize across pods. See our guide to scaling Cypress tests with Testkube for the full setup.
How do I test container health in Kubernetes?
Container health in Kubernetes is validated through liveness, readiness, and startup probes defined in the Pod spec. Beyond probes, in-cluster smoke tests confirm that a container actually responds to traffic after it reports ready. A common pattern is a Kubernetes Job that runs a curl health check against the service endpoint immediately after deployment.
Is container testing different from pod testing?
In practice, yes. Container testing focuses on the application running inside the container: the code, dependencies, and runtime behavior. Pod testing extends that to the Kubernetes wrapper around it: probes, init containers, sidecars, resource limits, volume mounts, and network configuration. A test that passes for the container can still fail at the pod level if the Pod spec is misconfigured.


About Testkube
Testkube is the open testing platform for AI-driven engineering teams. It runs tests directly in your Kubernetes clusters, works with any CI/CD system, and supports every testing tool your team uses. By removing CI/CD bottlenecks, Testkube helps teams ship faster with confidence.
Get Started with a trial to see Testkube in action.





