Creating pods across data centres

2/24/2020

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

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

-- greenhorntechie
kubernetes
openshift

1 Answer

2/24/2020

You can add labels(arbitary key value pairs) on the nodes of your kubernetes cluster.

kubectl label nodes node1 datacenter=xyz

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

As an example of using nodeselector

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

Official docs here with more details and examples.

-- Arghya Sadhu
Source: StackOverflow