Advanced Scheduling and Node Selectors

Overview

A node selector specifies a map of key-value pairs. The rules are defined using custom labels on nodes and selectors specified in pods.

For the pod to be eligible to run on a node, the pod must have the indicated key-value pairs as the label on the node.

If you are using node affinity and node selectors in the same pod configuration, see the important considerations below.

Configuring Node Selectors

Using nodeSelector in a pod configuration, you can ensure that pods are only placed onto nodes with specific labels.

  1. Ensure you have the desired labels (see Updating Labels on Nodes for details) and node selector set up in your environment.

    For example, make sure that your pod configuration features the nodeSelector value indicating the desired label:

    1. apiVersion: v1
    2. kind: Pod
    3. spec:
    4. nodeSelector:
    5. <key>: <value>
    6. ...
  2. Modify the master configuration file, /etc/origin/master/master-config.yaml, to add nodeSelectorLabelBlacklist to the admissionConfig section with the labels that are assigned to the node hosts you want to deny pod placement:

    1. ...
    2. admissionConfig:
    3. pluginConfig:
    4. PodNodeConstraints:
    5. configuration:
    6. apiversion: v1
    7. kind: PodNodeConstraintsConfig
    8. nodeSelectorLabelBlacklist:
    9. - kubernetes.io/hostname
    10. - <label>
    11. ...
  3. Restart OKD for the changes to take effect.

    1. # master-restart api
    2. # master-restart controllers

If you are using node selectors and node affinity in the same pod configuration, note the following:

  • If you configure both nodeSelector and nodeAffinity, both conditions must be satisfied for the pod to be scheduled onto a candidate node.

  • If you specify multiple nodeSelectorTerms associated with nodeAffinity types, then the pod can be scheduled onto a node if one of the nodeSelectorTerms is satisfied.

  • If you specify multiple matchExpressions associated with nodeSelectorTerms, then the pod can be scheduled onto a node only if all matchExpressions are satisfied.