Network policies

A NetworkPolicy controls the traffic that is allowed to and from Pods at the IP address and port level.

A NetworkPolicy controls the traffic that is allowed to and from Pods at the IP address and port level (OSI layers 3 and 4). You select Pods with labels and define which ingress and egress traffic is allowed. A NetworkPolicy has an effect only if the network plugin enforces it. Calico, the default plugin in Cloudera Cloud Factory, does.

By default, Pods are non-isolated: they accept traffic from any source and can send traffic to any destination. A Pod becomes isolated for a direction when at least one NetworkPolicy selects it for that direction. Policies are additive, so there are no conflicts, and the order of evaluation does not matter. For a connection to work, the egress policy of the source Pod and the ingress policy of the destination Pod must both allow it.

Key defaults and limits

  • Policies apply to TCP, UDP, and SCTP only.
  • A policy selects namespaces by label. Every namespace has the label kubernetes.io/metadata.name.
  • The endPort field, which defines a range of ports, is stable since Kubernetes 1.25.
  • To deny all ingress or egress traffic in a namespace, create a policy with an empty podSelector and no allow rules for that direction.
  • The behavior of policies for Pods that use hostNetwork is undefined.
  • A NetworkPolicy cannot enforce TLS, log network events, define explicit deny rules, or target a Service by name.

For more information, see Network Policies.