by Isovalent
In Namespace
Outside Cluster
Any endpoint
In Namespace
Any pod
In Cluster
Everything in the cluster
Outside Cluster
Any endpoint
In Namespace
Any pod
In Cluster
Everything in the cluster
Kubernetes DNS
Policy Rating

Can't load policy YAML

Welcome to the Network Policy Editor!

This tutorial will teach you how to create a network policy using the Editor. It explains basic network policy concepts and guides you through the steps needed to achieve the desired least-privilege security and zero-trust concepts.

Step 1. What pods do you want to secure?

First, select the pods to which the policy should be applied by matching pod labels. A network policy can be applied to an individual pod, a group of pods, an entire namespace, or an entire cluster.1 If the pod selector is left empty, the policy will be applied to all the pods in a namespace.

1 Clusterwide Policies are not yet implemented in the Editor.

Specify the pod selector, policy name and namespace

Step 2: Introduce an ingress and egress default deny posture.

The standard network security posture of Kubernetes allows all network traffic. You are responsible for restricting all communication by introducing a “default deny” posture and then allowing only the desired network communication. This can be done incrementally — that is, you can place individual pods, groups of pods, or entire namespaces into a default deny posture. Or you can tackle ingress (traffic into the pod) and egress (traffic out of a pod) communication separately.

An empty policy with only a pod selector does not enforce any rules. By adding a rule (even an empty rule), the selected pods will change into a default deny posture for the selected traffic direction. Decide if you want to set ingress, egress, or both to a default deny posture by adding an empty rule.

For this tutorial, enable default deny for both ingress and egress.

Step 3. Allow Traffic to Kubernetes DNS

The pods will likely want to resolve DNS queries on port 53/UDP. Allow communication to Kubernetes DNS. Specifically, you should explicitly allow egress traffic to port 53/UDP only to kube-dns pods in the cluster, rather than allowing it to any endpoint on the Internet.

Advanced: When using Cilium Network Policies, you can enable DNS-proxy to observe and filter all DNS egress traffic for the selected pods.

Step 4. Allow Traffic in the Same Namespace

Decide if the pods chosen by the pod selector will communicate with other pods in the same namespace.

Note: To allow traffic between two pods, the egress side of the sending pod and the ingress side of the receiving pod must both allow traffic. This ensures compliance with zero-trust principles by allowing each pod to enforce its own policy instead of relying on the policies of other pods.

Allow all traffic in the same namespace
Allow ingress traffic from specific pods in the same namespace
Allow egress traffic to specific pods in the same namespace

Step 5. Allow Incoming Traffic from Outside the Cluster

All traffic from outside the cluster is currently dropped. Decide if the isolated pods should receive ingress traffic from outside the cluster.

Allow ingress traffic from outside the cluster

Step 6. Allow Outgoing Traffic from the Cluster

All traffic to endpoints outside of the cluster is currently dropped. You can allow egress traffic to the entire Internet; however, we recommend allowing traffic only to known DNS names, known CIDRs, or a specific port, like port 80 or 443, at the least.

Allow egress outside the cluster to certain ports
Allow egress outside the cluster to a DNS name
Allow egress outside the cluster to a CIDR

Step 7. Allow Cross-Namespace Traffic

Think about cross-namespace communications. Even if you allowed all ingress or egress from/to the entire Internet, the rules would not match the ingress or egress traffic coming from pods in other namespaces. If isolated pods might receive (ingress) or send (egress) traffic to pods in other namespaces, consider adding rules accordingly.

Allow ingress from certain pods in other namespaces
Allow egress to certain pods in other namespaces

Step 8. Allow Network-Based Liveness/Readiness Probes

If your pod uses network-based liveness or readiness probes, then these probes happen via the network. Kubernetes requires that all NetworkPolicy implementations automatically allow traffic from the host to the pod.

Advanced: Automatically allowing traffic from the host to the pod is not ideal based on the principles of least-privilege and zero-trust. Click here for more information on configuring Cilium so that traffic to the host relies instead on explicit policy to define the security posture.

Final: Download Resulting Policy

Congratulations! If you followed the tutorial, you now have a policy that you can enforce. To use network policies in Kubernetes, you must use a networking plugin that implements network policy specification; without it, the network policy will have no effect. One possible solution is Cilium. Continue by clicking the Download button and following the instructions.

Another hands-on way to learn about Cilium network policies by using the interactive labs from Isovalent.