Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 521 of 8028. Security and ObservabilityFree lesson

Validating Network Policy Enforcement with Traffic Probes

Use diagnostic tools to verify that your defined network policies are effectively blocking unauthorized connection attempts between isolated pod groups.

In this lesson, you will learn how to use lightweight diagnostic traffic probes to verify that your Network Policies are actively blocking unauthorized communication between pods.

By default, Kubernetes pods exist in a flat network where any pod can talk to any other pod. While NetworkPolicies allow you to enforce a "Zero Trust" architecture, a misconfigured selector can leave security gaps that are difficult to spot by simply reading YAML. To confirm your policies are effective, you must actively test connectivity using traffic probes.

Using Diagnostic Probes

A traffic probe is a temporary container—often a lightweight image like busybox or alpine—that you launch within your cluster to act as a "client" pod. By executing network commands from this probe, you can observe whether connection attempts are dropped or rejected as expected.

To validate your security posture, follow these steps:

  1. Deploy a Target: Ensure your application pod is running with a specific label (e.g., app=secure-service).
  2. Launch a Probe: Run an ephemeral pod in the same namespace (or a different one, depending on your policy scope):
    kubectl run net-probe --rm -it --image=busybox -- /bin/sh
    
  3. Attempt Connection: Inside the probe, attempt to reach the target pod using wget or nc (netcat):
    # Try to hit the target pod's IP on its listening port
    nc -zv <target-pod-ip> 80
    

Interpreting Results

If your NetworkPolicy is correctly configured, the connection attempt should either "time out" or be "refused." If the connection succeeds, your policy is not effectively isolating the traffic, and you should re-examine your podSelector or namespaceSelector logic.

Automating these probes in your CI/CD pipeline acts as a regression test. If a developer accidentally modifies a label or deletes a policy, your pipeline can catch the "leaky" connectivity before the code is deployed to production. Using these probes transforms your security policy from a static configuration file into a verifiable, living part of your cluster’s operational health.

Key Takeaway: Never assume a network policy works; verify its enforcement by actively probing connectivity between pods to confirm that unauthorized paths are successfully blocked.