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.
The oc get nodes command will return the list of nodes. Notice there are two worker nodes.
~]# oc get nodes
NAME STATUS ROLES AGE VERSION
my-node-infra-4k6z9 Ready infra 273d v1.11.0+d4cacc0
my-node-master-0 Ready master 273d v1.11.0+d4cacc0
my-node-worker-5n4fj Ready worker 273d v1.11.0+d4cacc0
my-node-worker-v8r9r Ready worker 273d v1.11.0+d4cacc0
Let's say you want to be able to specify the worker node that an application / container / deployment / pod will run. To accomplish this, you will need to label the worker nodes. The oc label node command can be used to apply one or more labels to a worker node. The worker node doesn't have to be labeled "region". You can pick any key value pair you would like.
~]$ oc label node my-node-worker-5n4fj region=east
node/my-node-worker-5n4fj labeled
~]$ oc label node my-node-worker-v8r9r region=west
node/my-node-worker-v8r9r labeled
The oc describe node command can be used to see the labels that have been applied to the worker nodes.
~]$ oc describe node my-node-worker-5n4fj
Name: my-node-worker-5n4fj
Roles: infra,worker
Labels: region=east
~]$ oc describe node my-node-worker-v8r9r
Name: my-node-worker-v8r9r
Roles: infra,worker
Labels: region=west
The oc edit command can be used to manually edit the deployment YAML. Here is an example of what your deployment YAML would have to have the pod created on the "east" or "west" worker node using nodeSelector.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
template:
spec:
nodeSelector:
region: west
Or, the oc patch command can be used.
~]$ oc patch deployment my-deployment --patch '{"spec":{"template":{"spec":{"nodeSelector":{"region":"east"}}}}}'
deployment.apps/my-deployment patched