As a resource of Kubernetes, NetworkPolicy uses label selectors to configure the firewall of Pods from infrastructure level. Without a specified NetworkPolicy, any Pod in the same cluster can communicate with each other by default. On the other hand, once a NetworkPolicy with rules is attached to a Pod, either it is for ingress or egress, or both, and all traffic that doesn't follow the rules will be blocked.
Before demonstrating how to build a NetworkPolicy, we should make sure the network plugin in Kubernetes cluster supports it. There are several CNIs that support NetworkPolicy: Calico, Contive, Romana (https://github.com/romana/kube), Weave Net (https://github.com/weaveworks/weave), Trireme (https://github.com/aporeto-inc/trireme-kubernetes ...