Testing Charts
1. Running Chart Tests
2. Creating Test Pods
Example: HTTP smoke test
apiVersion: v1
kind: Pod
metadata:
name: {{ include "myapp.fullname" . }}-test
annotations:
"helm.sh/hook": test
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
restartPolicy: Never
containers:
- name: curl
image: curlimages/curl:8.6.0
command: ["sh", "-c"]
args:
- curl -fsS http://{{ include "myapp.fullname" . }}:{{ .Values.service.port }}/healthz
3. Using Test Annotations
| Annotation | Value |
|---|---|
helm.sh/hook | test (legacy test-success, test-failure removed) |
helm.sh/hook-delete-policy | hook-succeeded, hook-failed, before-hook-creation |
helm.sh/hook-weight | Ordering between multiple tests |
4. Running Specific Tests
| Flag | Use |
|---|---|
--filter name=test-connection | Run only matching test pods |
5. Viewing Test Logs
| Flag | Effect |
|---|---|
--logs | Stream pod logs to terminal after each test |
6. Setting Test Timeout
| Flag | Default |
|---|---|
--timeout | 5m |
7. Filtering Test Results
Example: Inspect failed test pod
kubectl logs -n web {{ include "myapp.fullname" . }}-test
kubectl describe pod -n web {{ include "myapp.fullname" . }}-test
8. Cleaning Test Pods
| Strategy | How |
|---|---|
| Auto | Annotation hook-delete-policy: hook-succeeded |
| Manual | kubectl delete pod -l app.kubernetes.io/instance=<release> |
9. Testing with Different Values
Example: Per-env test matrix
for env in dev staging prod; do
helm template ./chart -f values-$env.yaml | kubectl apply --dry-run=client -f -
done
10. Automating Chart Tests
| Tool | Use |
|---|---|
chart-testing (ct) | CI-grade lint + install + test on PR diff |
helm-unittest plugin | Snapshot-based unit tests for templates |
GitHub Action helm/chart-testing-action | Pre-built CI integration |