<p>I have many namespaces and multiple services running on each namespace.</p>
<p>We are using calico plugin in our Kubernetes ckuster. I am looking for a way to restrict access b/w services/ingress.</p>
<p>Say, Service A, Service B and Service C are running in Namespace A.</p>
<p>I want Service B to access Service A, but not Service C. Can this be done with Networking policy in Kubernetes? Is an example available?</p>
<p>Also, I want no services from Namespace B accessing any services in Namespace A. But, I need some services from Namespace C accessing some services in namespace A.  Can this be done using calico?</p>

user1578872
<p>Yes this is entirely possible.</p>

<p>Kubernetes network policies support both ingress/egress rules. Also there are three types of traffic selectors:</p>

<ul>
<li>Based on ipBlock</li>
<li>Based on namespace selector</li>
<li>Based on pod selector</li>
</ul>

<p>You can create labels on your pods and used those label selectors for identifying the pods to apply the policies.</p>

<p>Here is the <a href="https://v1-9.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#networkpolicy-v1beta1-extensions" rel="nofollow noreferrer">link</a> for the K8S api documentation for network policies.</p>

<p>And this <a href="https://github.com/ahmetb/kubernetes-network-policy-recipes" rel="nofollow noreferrer">github</a> repository has lot of examples.</p>
