In Kubernetes, you can provide better granularity for your application deployments in terms of network isolation using network policies. Represented by NetworkPolicy objects, they define how groups of pods can communicate with each other and network endpoints in general—think of them as a basic firewall for enforcing network segmentation at layer 3 of the OSI model. Of course, they are not a substitution for advanced
The NetworkPolicy object uses label selectors in order to identify the pods that they are attached to. Similarly, label selectors and IP CIDRs are used for defining ingress and egress rule targets for these pods. A given network policy is used only if it has a label selector that matches a given pod. If there are no network policies matching a given Pod, it can accept any traffic.