<p>I have a pod with the label <code>app: jenkins-master</code> on <code>jenkins</code> namespace.</p>

<p>I also want to create an <code>nginx</code> deployment.</p>

<p>(for reasons beyond the scope of this question, the <code>nginx</code> deployment will reside in a different namespace)</p>

<p>I want these two pods to be (softly) scheduled on the same node so I am using the following pod spec in the deployment manifest</p>

<pre><code>spec:
  affinity:
    podAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - jenkins-master
</code></pre>

<p>How should I syntactically set the <code>namespace</code> value to <code>jenkins</code> in the above snipper?</p>

<p>(or even better state that I want this to be applicable across <code>all</code> namespaces?</p>

pkaramol
<p>You can specify optional associated list of namespaces</p>

<pre><code>spec:
  affinity:
    podAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - jenkins-master
        namespaces: 
        - namespacename1
        - namespacename2
</code></pre>

<p>As documented <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podaffinityterm-v1-core" rel="noreferrer">here</a></p>

<pre><code>namespaces
string array    namespaces specifies which namespaces the labelSelector applies to (matches against); null or empty list means "this pod's namespace"
</code></pre>
