Node Feature Discovery (NFD)

repository·master·Indexed 21 days ago

https://github.com/kubernetes-sigs/node-feature-discovery

A Kubernetes add-on that detects hardware features and system configurations on nodes and exposes them as Kubernetes node labels. NFD enables workloads to target specific hardware capabilities, such as CPU Turbo Boost, AVX, or AES-NI, using Kubernetes affinity and anti-affinity rules. The project includes components like nfd-master, nfd-worker, nfd-topology-updater, and nfd-gc, with deployment supported via OCI and legacy Helm repositories.

Tokens
58.4K
Snippets
177
Records
245
Agent score
74%

What's inside Node Feature Discovery

  1. Overview of NFD Custom Resources

    master

    NFD utilizes Kubernetes Custom Resources (CRDs) to manage feature state and topology:

    • NodeFeature: Used to represent node features and request that specific node labels be generated.
    • NodeFeatureRule: Used by nfd-master to perform custom labeling of nodes based on defined rules.
    • NodeResourceTopology: Created and updated by nfd-topology-updater to describe the hardware topology of node resources (e.g., NUMA nodes/zones).
  2. What is NFD-Topology-Updater and how does it work?

    master

    NFD-Topology-Updater is a component designed to run as a Kubernetes DaemonSet. Its primary purpose is to capture changes in allocated resources (such as CPU cores, memory, and devices) and update NodeResourceTopology custom resources accordingly. This allows for tracking allocatable resources on a per-zone basis (where a zone can be a NUMA node).

    Key Behaviors

    • Resource Accounting: It only accounts for resources exclusively allocated to Guaranteed Quality of Service pods.
    • Re-examination Triggers:
      • Interval-based: Nodes are re-examined at a regular interval defined by the -sleep-interval flag (default is 60s). Setting this to 0 disables re-examination.
      • Event-based: The updater can monitor the Kubelet checkpoint file (via the -kubelet-state-dir flag) to trigger updates whenever pod lifecycle events occur.
    • Resource Filtering: You can prevent the examination of specific resources using the -excludeList option.
  3. How NFD built-in labels are generated and managed

    master

    NFD (Node Feature Discovery) generates labels using separate modules called label sources. You can control which sources are enabled using the core.labelSources configuration option or the -label-sources CLI flag for nfd-worker.

    All built-in labels follow the namespace feature.node.kubernetes.io with the format: feature.node.kubernetes.io/<feature> = <value>.

    Important Lifecycle Note: NFD performs consecutive runs to keep labels up-to-date. If a feature is no longer detected during a run, its corresponding label is removed. This removal behavior applies even if you are using a whitelist (via -label-whitelist on nfd-master or core.labelWhiteList on nfd-worker).

  4. Reference: Feature matching logic (FeatureMatcher and MatchExpression)

    master

    NFD uses a hierarchical matching system to evaluate features against rules.

    FeatureMatcher: Specifies a set of FeatureMatcherTerm objects. All terms in a FeatureMatcher must match (AND logic).

    FeatureMatcherTerm: Defines requirements against a specific feature set. It uses matchExpressions to evaluate against elements in that set.

    MatchExpression: The core evaluation unit. It contains:

    • op: The operator to apply.
    • value: The value(s) to evaluate against.
    • type: The type of the value.

    MatchAny: Used within GroupRule or Rule to provide OR logic. If matchAny is provided, at least one of the specified MatchAnyElem must match.

  5. How NFD extension points work

    master

    NFD provides four primary extension points for vendor and application-specific labeling:

    1. NodeFeature custom resources: Used to communicate "raw" node features and direct node labeling requests to the nfd-master.
    2. NodeFeatureRule custom resources: Provides a way to deploy custom labeling and tainting rules via the Kubernetes API based on existing features.
    3. local feature source: A feature source for nfd-worker that creates labels by reading text files.
    4. custom feature source: A feature source for nfd-worker that creates labels based on user-specified rules.

    Note: When using NodeFeature objects, you must ensure RBAC rules are created for your extensions to allow them to manipulate these objects in their namespace.

  6. Use NodeFeatureGroup to create node pools

    master

    A NodeFeatureGroup resource is used to define logical pools of nodes based on specific feature requirements. This is useful for grouping nodes with similar hardware or software capabilities.

    Configuration (spec):

    • featureGroupRules: An array of GroupRule objects. A node belongs to the group if it satisfies the rules.

    Status (status):

    • nodes: An array of FeatureGroupNode objects representing the nodes in the cluster that currently match the specification.
  7. Use Extended Resources with NFD

    master

    NFD can create Kubernetes Extended Resources, allowing Pods to request specific hardware capacities (e.g., a specific amount of SGX EPC memory) and enabling the Kubernetes scheduler to match Pods to nodes with sufficient capacity.

    To configure this, use the extendedResources field within the NodeFeatureRule Custom Resource Definition (CRD).

    Note: NFD is not a replacement for device plugins; it is used to expose node features as resources for scheduling purposes.

  8. Tune the rolling-update pace for large clusters

    master

    The nfd-worker DaemonSet uses maxUnavailable: "10%" by default. In large clusters, this results in updates occurring in roughly ten waves. Because nfd-worker is stateless and node labels persist during pod restarts, you can tune this pace to control how quickly feature updates resume on nodes.

    To change the update strategy:

    • Set worker.updateStrategy.rollingUpdate.maxUnavailable to 1 to restore the standard Kubernetes behavior of updating one node at a time.
    • To use type: OnDelete, set rollingUpdate: null (since Helm performs a deep-merge on maps).

    Note for GitOps/Automated Upgrades: If using helm upgrade --wait or tools like Flux or Argo CD, ensure your timeout is large enough to cover the full rollout. A safe estimate is ceil(1 / maxUnavailable) × per-wave pod-ready time.

  9. Define image compatibility requirements using the Compatibility Specification

    master

    Image compatibility metadata (experimental v1alpha1) allows container image authors to define environment requirements using a specification similar to Node Feature Groups. This enables matching container requirements directly against features discovered on nodes by NFD.

    Schema

    • version (string, REQUIRED): The API version (e.g., v1alpha1).
    • compatibilities (array of objects, REQUIRED): A list of compatibility sets.
      • rules (object, REQUIRED): A reference to the NodeFeatureGroup API spec. This allows describing requirements using features discovered from NFD sources.
      • weight (int, OPTIONAL): Specifies the node affinity weight.
      • tag (string, OPTIONAL): Used for grouping or separating compatibility sets.
      • description (string, OPTIONAL): A brief description of the compatibility set.
    version: v1alpha1
    compatibilities:
    - description: "My image requirements"
      rules:
      - name: "kernel and cpu"
        matchFeatures:
        - feature: kernel.loadedmodule
          matchExpressions:
            vfio-pci: {op: Exists}
        - feature: cpu.model
          matchExpressions:
            vendor_id: {op: In, value: ["Intel", "AMD"]}
      - name: "one of available nics"
        matchAny:
        - matchFeatures:
          - feature: pci.device
            matchExpressions:
              vendor: {op: In, value: ["0eee"]}
              class: {op: In, value: ["0200"]}
        - matchFeatures:
          - feature: pci.device
            matchExpressions:
              vendor: {op: In, value: ["0fff"]}
              class: {op: In, value: ["0200"]}
  10. Understand NFD feature label formats

    master

    NFD discovers features across several domains and converts them into node labels. Most feature labels follow the prefix feature.node.kubernetes.io/<domain>-<feature-name>.

    Supported feature domains include:

    • CPU
    • Kernel
    • Memory
    • Network
    • PCI
    • Storage
    • System
    • USB
    • Custom (rule-based)
    • Local (based on files)

    Common label patterns include:

    • Boolean features: feature.node.kubernetes.io/<domain>-<feature-name>: "true"
    • Value-based features: feature.node.kubernetes.io/<domain>-<feature-name>: "<feature value>"
    {
      "feature.node.kubernetes.io/cpu-<feature-name>": "true",
      "feature.node.kubernetes.io/custom-<feature-name>": "true",
      "feature.node.kubernetes.io/kernel-<feature name>": "<feature value>",
      "feature.node.kubernetes.io/memory-<feature-name>": "true",
      "feature.node.kubernetes.io/network-<feature-name>": "true",
      "feature.node.kubernetes.io/pci-<device label>.present": "true",
      "feature.node.kubernetes.io/storage-<feature-name>": "true",
      "feature.node.kubernetes.io/system-<feature name>": "<feature value>",
      "feature.node.kubernetes.io/usb-<device label>.present": "<feature value>",
      "feature.node.kubernetes.io/<file name>-<feature name>": "<feature value>"
    }
  11. Understand Spiffe integration for NFD security

    master

    NFD supports an experimental Spiffe integration (KEP-1186) designed to improve security by signing NodeFeature Custom Resource (CR) specifications. This prevents malicious workloads from injecting false node features by ensuring that only features signed by a valid nfd-worker (using a private key from a Spiffe Verifiable Identity Document, or SVID) are propagated to nodes.

    How it works

    1. Identity: A single SVID is shared among all nfd-worker workloads.
    2. Signing: After feature discovery, nfd-workers fetch their private key from Spiffe and sign the NodeFeature CR spec. The signature is stored in the CR annotations under annotations.signature as a base64-encoded string.
    3. Verification: The nfd-master detects changes to the NodeFeature CR and verifies the signature using the corresponding public key. If the signature is invalid or missing (e.g., due to manual tampering), the changes are not propagated to the nodes.

    Configuration

    This feature is EXPERIMENTAL. Enabling or disabling Spiffe verification must be configured via command-line flags or a configuration file.

    Integration for 3rd Party Tools

    If you integrate third-party tools that interact with NFD data, you must create their respective SVIDs in the spire-server to allow their exposed data to be validated within this security model.