A default deny
An empty podSelector with Ingress in policyTypes, which denies all inbound traffic
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny
spec:
podSelector: {}
policyTypes:
- IngressPaste your NetworkPolicies and see what they actually permit, which pods they flip to default-deny, and whether anything still allows DNS. Because policies are additive, paste every policy in the namespace rather than one.
Or drop a file anywhere on this panel. Nothing is uploaded: the analysis runs in this tab.
The answer appears here
Paste on the left and press Resolve. Nothing leaves this tab.
Nothing else to flag.
No formatting problems, and nothing the rules object to. Worth remembering what that covers: this reads the file you pasted, not the account or cluster it will be applied to.
No finding matches that filter.
Real input you can load into the tool above. Each one shows a different thing going wrong, because that is what the tool is for.
An empty podSelector with Ingress in policyTypes, which denies all inbound traffic
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny
spec:
podSelector: {}
policyTypes:
- IngressTraffic permitted from one set of pods, and why adding this cannot carve an exception out of a deny
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-api
spec:
podSelector:
matchLabels:
app: db
ingress:
- from:
- podSelector:
matchLabels:
app: apiThese are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.
NetworkPolicy objects are accepted by the API server whether or not the CNI implements them. On a plugin without support they are stored and completely ignored.
Instead:Confirm the CNI enforces them. Calico, Cilium and Antrea do; some managed defaults do not.
podSelector: {} selects EVERY pod in the namespace. Combined with an empty ingress rule it is a namespace-wide default deny.
Instead:Read {} as all, and use it deliberately for default-deny policies.
Policies are additive and there is no deny rule and no precedence. Traffic is allowed if ANY policy allows it, so you cannot carve an exception out of a deny.
Instead:Narrow the deny instead, or select a different set of pods.
The YAML is simple. What makes NetworkPolicies hard is that the effect of one depends on all the others, and on what you left out.
The moment any policy applies Egress to a pod, everything not explicitly allowed is dropped, including UDP 53 to kube-dns. Every outbound connection then fails at name resolution rather than at connect, so the errors point at your application rather than at the policy. This is the most common way a NetworkPolicy takes down a working service, and it is reported before anything else.
Omit policyTypes and Kubernetes infers it: Ingress always, and Egress only when egress rules are present. So a policy with egress rules silently becomes default-deny for all other egress, and one without them does not. Reading that wrong is why people are surprised in both directions.
An absent namespaceSelector means the policy's own namespace. An empty one means every namespace in the cluster. They differ by two characters and mean opposite things, and the resolved output spells out which one each rule got.
169.254.169.254 serves instance credentials on AWS, Azure and GCP. A broad egress CIDR usually includes it, and a pod that can reach it can often assume the node's role, which is far more privileged than the workload. Flagged, with the except entry to add.
Three properties compound into something genuinely difficult to hold in your head, and none of them is obvious from a single document. Understanding them is most of the work; the YAML itself is simple.
There is no deny rule. A policy can only permit traffic, so you never reason about precedence or ordering the way you would with a firewall or with IAM. What you reason about instead is the union of everything permitted, which sounds simpler and is harder, because no single document contains the answer.
This is the property that surprises people. By default a pod accepts everything. The moment any policy selects it for a direction, that pod is denied everything in that direction except what policies explicitly allow. So adding one policy to permit one connection silently forbids every other connection that pod was making.
before any policy pod accepts everything
add a policy allowing ingress from the gateway
pod now accepts ONLY the gateway
the metrics scraper is now blocked,
and nothing in the policy mentions it Several policies can select the same pod, and the effect is the union of all their allowances. This is why reading one policy tells you nothing definitive: another document elsewhere in the namespace may permit the traffic you think is blocked. It also means you cannot revoke access by editing one policy: you have to find every policy that grants it.
kube-dns lives in another namespace and answers on UDP 53. A default-deny egress policy blocks it like anything else, so every name lookup fails. The application then reports connection errors for hosts it can no longer resolve, which reads as the network being entirely broken rather than one port being blocked. Any default-deny egress policy needs a companion rule allowing 53 to kube-system.
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53 NetworkPolicy is an API, not an implementation. The API server stores your policy whatever the cluster is running, and if the CNI plugin does not implement enforcement, nothing happens, no error, no warning, no traffic blocked. Calico, Cilium, Weave and Antrea enforce it; the AWS VPC CNI does not on its own, and flannel does not at all. Confirm enforcement before trusting any of this.