Kubernetes Network Policy Viewer

Paste 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.

Paste below, or drop a file anywhere on this panel

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.

Examples

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.

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:
    - Ingress

An allow rule

Traffic 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: api

Common mistakes

These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

  1. Expecting a policy to work with no CNI support

    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.

  2. Reading an empty podSelector as selecting nothing

    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.

  3. Adding an allow policy expecting it to override a deny

    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.

What it resolves

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 DNS trap, called out as critical

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.

policyTypes inference, done properly

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.

Empty selector versus absent selector

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.

Egress to the metadata endpoint

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.

Why NetworkPolicies are so hard to reason about

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.

They are allow-only, with no deny

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.

Selecting a pod flips it from allow-all to deny-all

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

And they are additive across every policy

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.

Default-deny egress breaks DNS first

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

And none of it works without a CNI that enforces it

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.

More kubernetes tools

Kubernetes YAML Generator Answer a few questions, get a manifest Kubernetes YAML Validator Is this YAML valid, and where is it wrong? Kubernetes Rollout & Probe Timing Restart loops, capacity dips and stuck drains Kubernetes Service Checker Will this Service have any endpoints? Kubernetes Manifest Diff What actually changed Kubernetes Resource Calculator What these manifests actually reserve Kubernetes RBAC Viewer Who can actually do what Kubernetes Deployment Generator See the capacity dip before you deploy Kubernetes Service Generator port, targetPort, and which one you meant Kubernetes StatefulSet Generator Stable names, and volumes that outlive you Kubernetes QoS Class Calculator And where you sit in the eviction order Kubernetes Node Capacity Planner Allocatable is not capacity Kubernetes Max Pods per Node Calculator The ENI limit, not the 110 default Kubernetes Label Selector Tester Which key failed, not just that one did Kubernetes Taint & Toleration Tester Tolerations permit, they do not attract Kubernetes Resource Name Validator RFC 1123 subdomain, label, or 1035 Kubernetes Label & Annotation Validator Why your image tag is not a legal label Kubernetes CrashLoopBackOff Guide The status is a timer, not a cause Kubernetes TLS Certificate Decoder When it expires, and what it covers Kubernetes ServiceAccount Token Decoder Bound or legacy, and when it dies Kubernetes imagePullSecret Generator The registry URL nobody gets right Kubernetes cert-manager Certificates Issuer scope, and the rate limit that costs a week Kubernetes Flux HelmRelease Generator With the source it cannot work without Kubernetes Helm Chart Generator Chart.yaml, values, and working templates Kubernetes Argo CD Application Generator The defaults that are off, turned on Kubernetes Ingress Generator pathType, and the TLS secret that fails quietly Kubernetes HPA Generator Why it says unknown and never scales Kubernetes SecurityContext Generator Pod level, container level, and which wins Kubernetes Probe Generator How long it gets to start before liveness kills it Kubernetes PVC Generator Access modes your storage can actually do Kubernetes ResourceQuota Generator And the LimitRange that stops it breaking deploys Kubernetes CronJob Generator The fields that decide whether it runs Kubernetes NetworkPolicy Generator With the DNS rule already in it Kubernetes RBAC Generator And what it actually grants Kubernetes PodDisruptionBudget Generator Can this budget ever be satisfied? Kubernetes API Deprecation Checker What breaks on the next upgrade Kubernetes Kubeconfig Viewer Read it without handing it to anyone Kubernetes Quantity Parser What 512Mi, 100m and 1e3 actually mean Kubernetes Multi-Document YAML Splitter One file per object, in apply order Kubernetes .env to ConfigMap & Secret Split the credentials out on the way Kubernetes Secret Decoder See what is actually in there Kubernetes Ingress to Gateway API Which annotations silently stop working Kubernetes Manifest Visualizer What points at what, and what points at nothing Kubernetes Patch Tester Which --type, and what it deletes Kubernetes kubectl JSONPath Tester kubectl's dialect, not generic JSONPath Kubernetes Node Affinity Tester Required excludes, preferred only scores Kubernetes Helm Values Diff A missing key is a third value Kubernetes Pod and Service CIDR Fixed at cluster creation Kubernetes Secret Encoder base64 is not encryption Kubernetes API Version Checker Will this apply on that cluster Kubernetes Go Template Tester Go truthiness is not JavaScript's Kubernetes Cluster Cost Estimator At your rates, not a price table Kubernetes Kustomize Build Transformers run in kustomize's order Kubernetes Helm Chart Validator version is SemVer, appVersion is not

Elsewhere on the site