Run an OpenShift pod on a specific node by hostname

In your pod or buildconfig yaml you can specify which nodes the pod should run on, generally by specifying one or more of the labels assigned to the appropriate nodes. For instance {"zone":"east"}.

Sometimes you want to be more specific and have a pod run on a very specific host. To find out which labels are available for the nodes, run the following command:

$ oc get nodes --show-labels

Example output:

NAME                    STATUS                     AGE       VERSION             LABELS
infra-0    Ready                      48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2s_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=infra-0,logging-infra-fluentd=true,logging=true,region=infra,type=infra,zone=default
infra-1    Ready                      48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2s_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=1,kubernetes.io/hostname=infra-1,logging-infra-fluentd=true,logging=true,region=infra,type=infra,zone=default
master-0   Ready,SchedulingDisabled   48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=master-0,logging-infra-fluentd=true,logging=true,openshift-infra=apiserver,type=master,zone=default
master-1   Ready,SchedulingDisabled   48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=master-1,logging-infra-fluentd=true,logging=true,type=master,zone=default
master-2   Ready,SchedulingDisabled   48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=1,kubernetes.io/hostname=master-2,logging-infra-fluentd=true,logging=true,type=master,zone=default
node-0     Ready                      48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2s_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=node-0,logging-infra-fluentd=true,logging=true,type=app,zone=default
node-1     Ready                      48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2s_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=1,kubernetes.io/hostname=node-1,logging-infra-fluentd=true,logging=true,type=app,zone=default
node-2     Ready                      48d       v1.7.6+a08f5eeb62   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/instance-type=Standard_E2s_v3,beta.kubernetes.io/os=linux,failure-domain.beta.kubernetes.io/region=canadaeast,failure-domain.beta.kubernetes.io/zone=0,kubernetes.io/hostname=node-2,logging-infra-fluentd=true,logging=true,type=app,zone=default

From this you will see that each node has a kubernetes.io/hostname label. You can use this in your annotations for the pod of buildconfig.

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
spec:
  template:
    spec:
      nodeSelector:
        kubernetes.io/hostname: node-0

Leave a Reply

Your email address will not be published. Required fields are marked *

*