How to Configure Kube Network Policy
A kube network policy controls which pods can send and receive traffic inside your cluster. You set it up by matching pod labels and defining allowed ingress and egress paths. By default, every pod in a cluster can talk to every other pod. This open design helps new teams move fast at first. Still, an attacker who gets into one pod can reach everything else. Setting up strict traffic rules stops lateral movement across your namespaces. How a kube network policy controls pod traffic A kube ne
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
A kube network policy controls which pods can send and receive traffic inside your cluster. You set it up by matching pod labels and defining allowed ingress and egress paths.
By default, every pod in a cluster can talk to every other pod. This open design helps new teams move fast at first. Still, an attacker who gets into one pod can reach everything else. Setting up strict traffic rules stops lateral movement across your namespaces.
How a kube network policy controls pod traffic
A kube network policy works at layer three and layer four of the network stack. It checks the IP addresses and port numbers of packets moving between workloads. The cluster API stores your rule, and your container network plugin enforces it. If your cluster network plugin does not support policies, your rules have no effect. You must pick a plugin that reads policy objects and blocks unmatched packets.
Each rule uses label selectors to pick a target group of pods. Once a pod matches a policy, the cluster isolates that pod for that direction. For example, an ingress rule blocks all incoming traffic except what you allow. An egress rule blocks all outgoing traffic except the destinations you list. You can allow traffic from specific pod labels, whole namespaces, or IP blocks.
The safest starting point is a default deny rule in every namespace. A default deny rule selects all pods in the namespace and allows nothing. After you put this base rule in place, no pod can talk without permission. Next, you add small allow rules for each app pair that must talk. Your web app gets a rule to talk to your backend API port. Your backend API gets a rule to reach the database port. Everything else stays blocked by default.
How to check your setup and see what keeps the session active
Writing traffic rules is only half of the job for platform teams. You must test each path to confirm the network plugin drops unwanted packets. Run a test pod in the same namespace and try to reach blocked ports. Then run a test pod in a different namespace to check cross-namespace rules. Check the network plugin flow logs to see dropped and allowed packet counts. Review your policies often so old labels do not leave dead rules behind.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Keep in mind that pod labels are not strong cryptographic identities. Any user who can edit pod labels can move a pod into an allowed group. You must pair network rules with strict role permissions on your cluster API. Only trusted deployment pipelines should have permission to change pod labels or namespaces.
Even a strict network rule only controls where a packet can travel. Once an allowed pod or user opens a session, the network rule stops checking. It cannot see which person is running commands inside an allowed pod. It cannot inspect database queries or API calls riding inside an allowed port. It also cannot rewrite sensitive fields like emails, phone numbers, or card numbers in results. To control what happens inside an open session, teams need inspection above the network layer.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Why is my kube network policy not blocking any traffic?
Your cluster needs a container network plugin that supports policy enforcement. Standard cluster installs often use basic networking that ignores policy objects until you upgrade the plugin.
Do network policies block traffic from outside the cluster?
Yes, ingress rules can filter external traffic using IP block ranges. Still, load balancers and node ports often rewrite source IP addresses before packets reach the pod.
What happens when two policies select the same pod?
Network rules in a cluster are additive and never conflict with each other. If two rules select the same pod, the pod allows the combined traffic of both rules.
Related guides
In this post