<p>I use 1 master 2 workers Kubernetes Cluster.
master and 1. worker: at location a
2. worker: at location b.</p>

<p>Location a and b is very far from each other.</p>

<p>I want to run the pods at location a, but if a down it is created at location b.</p>

<p>I want to create a pod in the worst scenario at location b.</p>

<p>How can I do this in Kubernetes?</p>

public_html
<p>This is a community wiki answer.</p>

<p>As @Burak mentioned in his comment:</p>

<p>What you're looking for is <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-affinity" rel="nofollow noreferrer">node affinity</a>:</p>

<blockquote>
  <p>– it allows you to constrain which nodes your pod is eligible to be
  scheduled on, based on labels on the node.</p>
  
  <p>Node affinity is specified as field nodeAffinity of field affinity in
  the PodSpec.</p>
  
  <p>Here’s an example of a pod that uses node affinity:</p>
</blockquote>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/e2e-az-name
            operator: In
            values:
            - e2e-az1
            - e2e-az2
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
  containers:
  - name: with-node-affinity
    image: k8s.gcr.io/pause:2.0
</code></pre>

<p>You can find all the necessary details in the linked documentation.</p>

<p>Please let me know if that helped. </p>
