Free tool
Kubernetes Network Policy Builder
Runs in your browser, with no sign-up and nothing to install.
This Kubernetes network policy builder creates NetworkPolicy YAML from a form, so selectors, ports and policy types come out in the correct structure. It runs in your browser and sends nothing to a server. It checks names, labels, ports and IP ranges as you type. Review the output and test it before production.
How do you use the network policy builder?
Enter the policy name, namespace and the labels of the pods to protect. Choose whether to restrict inbound traffic, outbound traffic or both, then add a rule for each allowed connection. The YAML updates as you type, and notes below it explain anything you should check.
- Ports accept
TCP/443,UDP/53, ranges such asTCP/8000-9000, or a named pod port. A number without a protocol means TCP. - Namespace accepts a name such as
frontend, which the builder converts to thekubernetes.io/metadata.namelabel, or labels such asteam=a,env=prod. - Any peer with ports allows those ports from anywhere. Any peer without ports allows everything in that direction.
How does the builder handle AND and OR?
Each rule’s selectors stay in one list item, which Kubernetes treats as AND. “Specific pods in a namespace” therefore means those pods, in those namespaces. Separate rules become separate list items, which Kubernetes treats as OR. Our guide to Kubernetes microsegmentation shows why one misplaced dash changes the meaning.
What are the builder’s limits?
The builder produces standard networking.k8s.io/v1 NetworkPolicy only, not CiliumNetworkPolicy or Calico resources. It validates format, but it can’t see your cluster, so it can’t tell you whether a label exists. Standard policies also can’t express deny rules, logging or layer 7 rules. For those, see how plugins compare in the guide above and in the best microsegmentation tools.
To work out which rules you need, try the flow log policy drafter.
Sources
- Kubernetes, Network Policies: kubernetes.io/docs/concepts/services-networking/network-policies
- Kubernetes, NetworkPolicy API reference: kubernetes.io/docs/reference/kubernetes-api/policy-resources/network-policy-v1
Frequently asked questions
How do I create a default-deny policy with this builder?
Leave target pod labels empty so that the policy selects every pod in the namespace, choose the directions you want, and remove all rules. Add the DNS option if you restrict egress and your pods need name resolution.
Why does the builder add policyTypes every time?
Because omitting it can change what a policy does. Kubernetes always sets Ingress but sets Egress only if an egress section exists, so a deny-all egress policy without policyTypes would not restrict egress.
Does the policy work on any cluster?
Only if your network plugin enforces NetworkPolicy. Without a plugin that implements it, the resource has no effect. Test in a non-production namespace, and confirm that traffic is blocked as you expect.
Is the DNS rule from the Kubernetes documentation?
No. The Kubernetes page we used warns that default-deny egress blocks DNS but doesn't give an example. The builder's rule is our own, based on the documented semantics, and it assumes the common k8s-app=kube-dns label in kube-system. Check your cluster.
Related articles
Kubernetes Microsegmentation: Network Policies, Limits and Plugins
How to segment a cluster with Kubernetes NetworkPolicy, and when you need more.