1001Ferramentas
🛡️Dev

Kubernetes NetworkPolicy Generator

Generate a Kubernetes NetworkPolicy in YAML (deny-by-default or allow by label) to control traffic between pods. Harden the network security of your cluster.

YAML

NetworkPolicy: closing traffic between pods

By default, in a Kubernetes cluster every pod talks to every pod. There is no isolation between namespaces or between applications — the database accepts connections from the reporting service, from the frontend and from anything compromised that happens to be running there. NetworkPolicy is the resource that closes that, and its model contains an inversion that catches people out.

Enter the name and the label of who may come in, and the page assembles the manifest. The inversion is this: while no policy selects a pod, it accepts everything; as soon as the first policy selects it, it starts refusing everything not explicitly allowed. In other words, creating a restrictive policy is not what closes the door — what closes it is a policy coming to exist that points at that pod.

Two things regularly surprise people. The first is that the policy only works if the cluster network plugin implements it: with some simpler plugins the manifest is accepted and ignored, which gives a false sense of isolation. The second is that rules are additive — several policies selecting the same pod add up their permissions and never restrict one another.

Frequently asked questions

How do I block all incoming traffic in a namespace?
With a policy selecting every pod, through an empty selector, and declaring no ingress rules at all. That is the default-deny pattern: the pods become selected, and since nothing is allowed, nothing gets in. Specific policies allowing what is needed come afterwards.
Why did my policy have no effect?
Almost always because the network plugin does not implement the resource. Several of the simpler plugins accept the object and do nothing. Check which one is in use: those that genuinely implement it include Calico, Cilium and Weave. Without support, no policy works.
Does the policy cover outgoing traffic too?
It does, but only if declared: the policy types are independent. A policy dealing only with ingress does not restrict the pod's egress, even though the pod is selected. Closing both directions means declaring both explicitly.

Related Tools