If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
There are a few different ways to run a pod on a specific node.
The oc new-app command is used to deploy an application. There are various ways to deploy an app.
The scheduler is responsible for determining which worker node a resource should get created on. For example, when deploying a new application to OpenShift, the scheduler determines which worker node the pod should be created on, typically the worker node with the most available memory and CPU. Check out my article on the default scheduler.
With podAffinity, you will first label a pod with any key value pair that you would like. Let's say my-pod-c4v5h is labled region=east.
~]$ oc label pod my-pod-c4v5h region=east pod/my-pod-c4v5h labeled
And get oc get pods --output wide command can be used to see that the node the pod in running on (worker-hsjrp in this example).
~]# oc get pods --output wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED MODE my-pod-c4v5h 1/1 Running 0 8d 10.142.118.51 worker-hsjrp <none>
Now let's say you have another pod (my-pod-zm7d6) that you want to ensure is run on the same node (worker-hsjrp). You could update the pods YAML to have the following podAffinity to have the pod run on the worker node that is labeled region=east.
With podAffinity, the scheduling of the pod on a node can either be preferred or required. Execution basically means "running pods" thus IgnoredDuringExecution means that nodeAffinity will have no impact on currently running pods. On the other hand, with Taint and Toleration, NoExecute can be used to terminate running pods.
The following operators can be used with matchExpression.
apiVersion: apps/v1 kind: Deployment metadata: name: my-pod-zm7d6 spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: matchExpressions: - key: region operator: In values: - east