Skip to main content

Kubernetes NetworkPolicy Builder

Visually configure Kubernetes NetworkPolicy rules. Add ingress and egress rules with pod selectors, namespace selectors, and IP blocks, then get a validated, copy-ready YAML manifest.

✓ Pod & namespace selectors ✓ IP block (CIDR) rules ✓ TCP/UDP port configuration ✓ Ingress & egress pipelines ✓ Live YAML with validation
Presets:

Policy Target

Ingress Rules

No ingress rules — all inbound traffic is denied.

NetworkPolicy YAML

 

Validation

Apply Commands

 

Frequently Asked Questions

What is a Kubernetes NetworkPolicy and what does it actually do?▼

A NetworkPolicy is a Kubernetes resource that defines how pods communicate with each other and with external endpoints. By default, all pods can communicate freely — a NetworkPolicy selects pods via labelSelector and restricts which traffic is allowed. Crucially, NetworkPolicy requires a CNI plugin that enforces it: Calico, Cilium, Weave Net, or Antrea. Flannel does NOT enforce NetworkPolicy. Creating a policy with an empty podSelector {} applies it to all pods in the namespace, immediately defaulting to deny-all.

What is the difference between ingress and egress in NetworkPolicy?▼

Ingress rules control inbound traffic — which sources can send traffic TO the selected pods. Egress rules control outbound traffic — where the selected pods can SEND traffic. If you specify an ingress block, only the listed sources are allowed; all other inbound traffic is denied. Same for egress. If you omit the ingress or egress block entirely, it is not restricted by this policy. To create a default deny-all, create a NetworkPolicy that selects all pods but has empty ingress: [] and egress: [] arrays.

How do namespaceSelector and podSelector work together in NetworkPolicy rules?▼

In a NetworkPolicy from/to rule, namespaceSelector selects entire namespaces (all pods in matching namespaces), podSelector selects pods within the same namespace as the policy, and you can combine them. If you put BOTH in the same rule object (using AND logic): { namespaceSelector: {...}, podSelector: {...} } — it selects pods matching podSelector WITHIN namespaces matching namespaceSelector. If you use separate list items (OR logic), each is an independent source. This AND vs OR distinction is critical and a common source of bugs.

How do I allow DNS resolution in a deny-all egress policy?▼

DNS uses UDP and TCP port 53. If you create a deny-all egress policy, pods lose DNS resolution. Always add an explicit egress rule allowing port 53 to your cluster's DNS service: { ports: [{ port: 53, protocol: UDP }, { port: 53, protocol: TCP }], to: [{ namespaceSelector: { matchLabels: { kubernetes.io/metadata.name: kube-system } } }] }. Without this, pods cannot resolve service names, breaking all service discovery. This is the most common mistake when implementing egress policies.

What is an ipBlock and when should I use it?▼

ipBlock allows specifying a CIDR range as a traffic source or destination. Use it for: allowing traffic from external load balancers or specific IP ranges (office IPs, VPN CIDRs), allowing egress to external APIs (e.g. 0.0.0.0/0 except internal RFC1918 ranges), or blocking access to cloud metadata endpoints (169.254.0.0/16 via except). The except field within ipBlock lets you exclude sub-ranges from a broader CIDR. ipBlock cannot reference pod or namespace labels — use podSelector/namespaceSelector for internal cluster traffic.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →