liveBook · Manning

Affinity

As explained in Machine Learning Platform Engineering

A Kubernetes affinity configuration expresses scheduling preferences or requirements that influence which nodes may run a pod.

Affinity schedules a pod toward nodes matching declared labels or resource characteristics. In Kubeflow notebooks, it helps operators direct workloads to suitable nodes, including nodes reserved for GPUs or different CPU capacities. section 7.1.3 section 7.1.4

Use affinity to make notebook placement explicit and operationally manageable:

  • Match node labels through node affinity rules; the example selects nodes whose compute label is small or xl. section 7.1.4
  • Expose several configurations in the Kubeflow UI, or make a default configuration read-only to limit launch locations. section 7.1.4
  • Combine affinity with taints and tolerations when powerful or specialized nodes must be restricted rather than merely preferred. section 7.1.3 section 7.1.4

Balancing small and powerful CPU nodes

Offer small-cpu-node and xl-cpu-node choices. Default ordinary notebooks to nodes labeled compute=small, while allowing workloads that need more capacity to select compute=xl. Because the shown affinity rule targets matching nodes without pairing it with a taint, an xl node can still accept pods when smaller nodes are full. section 7.1.4

Listing 7.3 Node affinity ConfigMap
 affinityConfig:
    value: ""
    options:
      - configKey: "small-cpu-selector"
        displayName: "small-cpu-node"
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
                - matchExpressions:
                    - key: "compute"
                      operator: "In"
                      values:
                       - "small"
      - configKey: "xl-cpu-selector"
        displayName: "xl-cpu-node"
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
                - matchExpressions:
                    - key: "compute"
                      operator: "In"
                      values:
                       - "xl"

Inspect the complete ConfigMap structure for two node-affinity choices using requiredDuringSchedulingIgnoredDuringExecution and nodeSelectorTerms. section 7.1.4

How Machine Learning Platform Engineering covers it

How deep it goes
Shows production configuration through labels, selector terms, UI defaults, and taint interactions, but does not detail scheduler internals.
Examples
Uses small-cpu and xl-cpu selectors, compute labels, GPU-capable nodes, and a Kubeflow node-affinity ConfigMap.
What it assumes
Assumes familiarity with Kubernetes pods and node labels while explaining affinity and tolerations through notebook configuration.
What you can do after
Operate/configure Kubeflow notebook placement through labeled-node affinity choices and coordinated taints and tolerations.
How it connects
Connects affinity with Kubernetes pods, node labels, node taints, tolerations, GPUs, and Kubeflow notebook configuration.

Also explained in

Compare how 6 books explain affinity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.