CICD-282 · NetworkPolicy validation
Encyclopedia · Advanced Kubernetes operations · All snippets
Previous · CICD-281 · Next · CICD-283
1. Where it fits
- Placement trusted cluster validation step.
- Prerequisites kubectl, isolated cluster or namespace and installed CRDs when named.
- Platforms kubernetes, local-lab.
2. Copy the snippet
bash
kubectl -n staging apply --dry-run=server -f manifests/networkpolicy.yaml
kubectl -n staging exec deploy/allowed-client -- curl --fail --max-time 5 http://web/healthz
if kubectl -n staging exec deploy/blocked-client -- curl --fail --max-time 5 http://web/healthz; then exit 1; fi3. How it works
The intended NetworkPolicy is schema-checked first. Probes from pre-labeled clients then distinguish allowed from blocked connectivity against the active policy.
A positive and negative client probe establish the policy boundary.
flowchart TD N1["NetworkPolicy"] N2["Allowed client probe"] N1 --> N2 N3["Blocked client probe"] N1 --> N3 N4["Accept expected connection"] N2 --> N4 N5["Reject unexpected connection"] N3 --> N5
4. Verify the result
Requires policy-capable CNI and predeployed curl clients. Resolve DNS from both clients first to avoid mistaking DNS failure for a successful deny.
Watch for. Confine the test and all synthetic traffic to an authorized, disposable lab. Check cleanup even after a failing assertion.
Validation syntax-validated (Bash parse). Status definitions.