<p>I have two Kubernetes deployments (DeploymentA and DeploymentB) and I am wondering that is there a way to whitelist all incoming traffic from DeploymentB in DeploymentA? So that DeploymentA can be accessed only via DeploymentB.</p>

<p>ClusterIP service can be used to access deployments for internal communication in Kubernetes but How can I whitelist all the requests coming from a specific deployment(or its pods) in another deployment? Is there a way for example to get all possible ip addresses of the pods of a specific deployment in order to whitelist them?</p>

<p><strong>Edit 1:</strong></p>

<p>I have a web application which is open to Internet but a specific part of it has to be accessible only from a specific deployment. To implement that, I need to specify the IP-addresses or somehow names of the deployments which should have access.</p>

<p>Thank you!</p>

Patric
<p>You can use <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">Network policy</a></p>
<blockquote>
<p>A network policy is a specification of how groups of pods are allowed to communicate with each other and other network endpoints.</p>
<p>NetworkPolicy resources use labels to select pods and define rules which specify what traffic is allowed to the selected pods.</p>
</blockquote>
