<p>a newbie question related to Kubernetes / OpenShift. The physical infrastructure for our OpenShift cluster is spread across two data centres. </p>

<p>When I create pods, how can I guarantee / choose a particular node / data centre where it would be located?</p>

greenhorntechie
<p>You can add labels(arbitary key value pairs) on the nodes of your kubernetes cluster. </p>

<pre><code>kubectl label nodes node1 datacenter=xyz
</code></pre>

<p>then you can either use nodeselector or nodeaffnity in the pod spec to schedule a pod to a node with a specific label.</p>

<p>As an example of using nodeselector</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    datacenter: xyz
</code></pre>

<p>Official docs <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" rel="nofollow noreferrer">here</a> with more details and examples.</p>
