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.
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.
Related Products
on GumroadPremium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad →GitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
Kubernetes Resource Estimator
Estimate total Kubernetes cluster CPU and memory requirements. Input pods, replicas, and resource requests/limits to get cluster totals, requests vs limits analysis, and a ready-to-use ResourceQuota YAML.
Open free tool →
Kubernetes Resource Calculator
Calculate total CPU and memory requirements for your Kubernetes workloads. Input resource requests and limits per pod, replica count, and get cluster resource usage with cloud cost estimates.
Open free tool →
Kubernetes Resource Calculator
Calculate K8s resource requests and limits. Input CPU cores, memory per pod, replica count. Output cluster resource needs, HPA config, namespace quota YAML.
Open free tool →
More Free Tools
Related Articles
Zero-Trust Architecture Implementation Guide for Developers 2026
Practical zero-trust architecture guide for developers: identity verification, network segmentation, service mesh, mTLS, and step-by-step implementation roadmap.
Essential Kubernetes Tools for Modern DevOps Teams in 2026
A practical guide to the most important Kubernetes tools in 2026, covering cluster management, observability, security, CI/CD integration, and developer productivity for teams running Kubernetes at scale.
Cilium Service Mesh vs Istio vs Linkerd: Kubernetes Networking 2026
Comprehensive comparison of Cilium, Istio, and Linkerd for Kubernetes service mesh in 2026. eBPF networking, performance benchmarks, mTLS, observability, and when to use each.
Docker Compose vs Kubernetes for Small Teams 2026
Should small teams use Docker Compose or Kubernetes in 2026? Compare production viability, K3s as a middle ground, Kompose migration, and the real costs of managed Kubernetes for teams under 20.
Docker Compose vs Kubernetes: When to Use Each (2026)
A practical guide to choosing between Docker Compose and Kubernetes in 2026. Compare complexity, use cases, cost, and learn when to migrate from one to the other.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →