<p>I can resolve a DNS name on the internal kubernetes DNS with a value like: <a href="http://serviceNameExampleAbc.default.svc.cluster.local" rel="nofollow noreferrer">http://serviceNameExampleAbc.default.svc.cluster.local</a> where <code>serviceExampleAbc</code> relates to the IP of the service by name <code>serviceExampleAbc</code>...</p>
<p>However, how can I instead only resolve this to the service IP only if it has a specific label to it?</p>
<p>For example <code>http://serviceNameExampleAbc.servicesWithXyzLabelOnly.default.svc.cluster.local</code> would only resolve to <code>serviceNameExampleAbc</code>'s IP <strong>if</strong> it has a label defined for it like below:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: serviceNameExampleAbc
  labels:
    xyz: abcxyzexmaple
...

</code></pre>

Chris Stryczynski
<p>You can use the K8s <strong><a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">network polcies</a></strong> to block the traffic across the namespace or services.</p>
<p>So with network policy, you will be able to restrict the traffic across the namespaces, PODs based on the labels, selectors etc.</p>
<p>With <strong>network policy</strong> service will be able to resolve the <strong>IP</strong> in <strong>DNS</strong> but the Network policy won't allow further to connect to <strong>end</strong> <strong>service</strong>.</p>
<p><strong>Example</strong></p>
<p>Allow traffic from some PODs in another namespace</p>
<pre><code>kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: web-allow-all-ns-db
spec:
  podSelector:
    matchLabels:
      app: web
  ingress:
    - from:
      - namespaceSelector:     #All pods in namespace with label app=db-ns
          matchLabels:
            team: operations  
        podSelector:           #Chooses pods with app=db
          matchLabels:
            app: db 
</code></pre>
<p>here is the list of policies you can refer : <a href="https://github.com/ahmetb/kubernetes-network-policy-recipes" rel="nofollow noreferrer">https://github.com/ahmetb/kubernetes-network-policy-recipes</a></p>
