Slurm Operator

repository·main·Indexed 43 days ago

https://github.com/slinkyproject/slurm-operator

A Kubernetes Operator for deploying and managing Slurm clusters, providing custom controllers and CRDs to handle the lifecycle of control-planes, worker nodes (NodeSets), and login nodes (LoginSets). It supports Kubernetes >= 1.29.0-0, integrates with cert-manager for TLS, and includes specialized NVIDIA DCGM integration for GPU-to-job mapping.

Tokens
42.3K
Snippets
93
Records
170
Agent score
56%

What's inside Slurm Operator

  1. What is Slurm?

    main

    Slurm is an open-source, fault-tolerant, and highly scalable cluster management and job scheduling system designed for Linux clusters. It functions as a workload manager by performing three primary roles:

    1. Resource Allocation: Allocates exclusive or non-exclusive access to compute nodes for a specified duration.
    2. Job Execution: Provides a framework to start, execute, and monitor work (typically parallel jobs) on allocated nodes.
    3. Contention Arbitration: Manages a queue of pending work to resolve resource contention.

    Slurm is relatively self-contained and does not require kernel modifications to operate. It supports various optional plugins for advanced features like accounting, backfill scheduling, topology-optimized resource selection, and multifactor job prioritization.

  2. Understand Slurm node [un]drain synchronization

    main

    The operator synchronizes Kubernetes node [un]cordon state to NodeSet pods and their Slurm nodes (v1.0.0-rc1):

    • When a Kubernetes node is cordoned, the corresponding NodeSet pods are also cordoned and their Slurm nodes are drained.
    • NodeSet pods remain cordoned until the Kubernetes node is uncordoned.
    • The operator checks if a Slurm node is already in the requested state before requesting the opposite to avoid race conditions with manual admin actions.
  3. How LoginSets work

    main

    A LoginSet is a set of homogeneous login nodes (submit nodes or jump hosts) used to manage user identity via SSSD.

    Like NodeSets, LoginSets support scaling to zero, making them compatible with Horizontal Pod Autoscalers (HPA) that support scale-to-zero functionality.

  4. Enable Node Pinning for StatefulSet NodeSets

    main

    When using scalingMode=StatefulSet, NodeSet pods are loosely mapped to Kubernetes nodes and can be rescheduled. To ensure a pod always returns to the same physical node after eviction, deletion, or maintenance, you can enable Node Pinning.

    How it works:

    • The pod is initially scheduled normally.
    • The controller records the mapping in status.nodeToOrdinal.
    • On recreation, the controller adds a Kubernetes node affinity to the pod to force it onto the recorded node.
    • If the node is unavailable, the pod stays in Pending until the node returns.

    When pinning is removed:

    • The Kubernetes node no longer exists.
    • The new NodeSet pod template no longer matches the recorded node (e.g., changes to affinity or nodeSelector).
    # Example: Enabling node pinning in a NodeSet CR
    apiVersion: slinky.slurm.net/v1beta1
    kind: NodeSet
    metadata:
      name: gpu-workers
    spec:
      pinToNode: true
      replicas: 4
  5. Note changes to NodeSet scaling and pod behavior in v0.2.0+

    main

    As of version 0.2.0, the following changes affect how NodeSets manage pods:

    • Scaling Model: The NodeSet controller now scales pods similarly to a StatefulSet rather than a DaemonSet.
    • Hostname Mapping: The NodeSet pod hostname is now set to compute.nodeset[].name.
    • Scale-in Logic: NodeSet pod scale-in now considers running Slurm jobs, and out-of-order scale-in for NodeSet pods is supported.
    • Status Fields: The NodeSet.Status fields have been changed.
  6. Understand Hybrid and Autoscaling Slurm architectures

    main

    The slurm-operator supports complex deployment patterns:

    Hybrid Slurm Clusters

    You can join bare-metal slurmd instances to a containerized Slurm cluster managed by the operator. This allows the cluster to utilize external services (like AD/LDAP, NFS, or MariaDB) that reside outside of Kubernetes.

    Autoscaling

    The operator facilitates autoscaling Slurm workers in response to workload fluctuations, leveraging Kubernetes' native resource autoscaling capabilities to scale the Slurm compute capacity.

  7. Configure networking for hybrid Slurm clusters

    main

    Slurm requires a fully connected network with bidirectional communication between all daemons and clients. Because Kubernetes NAT-type networks can impede this, choose one of two networking strategies:

    Host Network

    Avoids Kubernetes NAT by having Slurm pods use the Kubernetes node host network directly.

    • Pros: Simplest methodology.
    • Cons: Security implications; only one pod with hostNetwork: true can run on a Kubernetes node at a time; inherits node hostname and namespace.
    • Note: Controller and Accounting do not support this option due to Slurm configuration race conditions with Kubernetes.

    To use this, configure the pod as follows:

    hostNetwork: true
    dNSPolicy: ClusterFirstWithHostNet

    Network Peering

    Configures network peering so internal and external services can communicate directly.

    • Pros: Higher security; minimal Slurm configuration required.
    • Cons: Most complex methodology.
    • Implementation: Typically involves an advanced CNI (like Calico) with network peering (BGP) for bidirectional communication across Kubernetes boundaries. No special configuration is required for the Slurm helm chart itself.
  8. Configure NVIDIA IMEX for NVLink Systems

    main

    For NVIDIA GB200/GB300 NVL72 systems, Slurm-operator supports IMEX channels via the NVIDIA GPU DRA driver.

    Note: Slurm-operator relies on DRA to manage IMEX channels, so do not use custom prolog/epilog scripts for IMEX management as they may interfere with the DRA driver. Per-job IMEX configuration is not supported; instead, use a ComputeDomain to inject channels into the NodeSet.

    # 1. Define a ComputeDomain to inject channels
    apiVersion: resource.nvidia.com/v1beta1
    kind: ComputeDomain
    metadata:
      name: slurm-compute-domain
      namespace: slurm
    spec:
      channel:
        allocationMode: All
        resourceClaimTemplate:
          name: slurm-test-compute-domain
      numNodes: 0
    
    # 2. Configure Controller for IMEX
    controller:
      extraConfMap:
        SwitchType: "switch/nvidia_imex"
        SwitchParameters: ""
    
    # 3. Claim the channel in the NodeSet
    nodesets:
      slinky:
        slurmd:
          resources:
            claims:
              - name: compute-domain-channel
  9. How the Slurm Client Controller works

    main

    The Slurm Client Controller is an internal component of the operator responsible for managing Slurm Clients, which are used by other internal controllers to interact with Slurm.

    Lifecycle and Workflow

    1. Creation and Initialization

    • When a user creates a Controller Custom Resource (CR) via the Kubernetes API, the Slurm Client Controller watches the CRD.
    • The controller creates a new Slurm Client instance.
    • The Slurm Client instance performs an initial connection to the Slurm REST API to retrieve Slurm nodes and add events to the Slurm Event Channel for cache delta tracking.
    • The controller adds the initialized Slurm Client to an internal Slurm Client Map.
    • The controller pings the Slurm Control Plane via the Slurm Client to verify connectivity.
    • Finally, the controller updates the status of the Controller CR in the Kubernetes API.

    2. Deletion and Cleanup

    • When a user deletes the Controller CR, the Slurm Client Controller watches the deletion event.
    • The controller looks up the corresponding Slurm Client in the Slurm Client Map and removes it.
    • The Slurm Client instance is then garbage collected (GC) and destroyed.
  10. Configure TPU support in Slurm via GRES

    main

    When configuring Slurm to recognize TPUs, follow these critical requirements to ensure stability and device access:

    1. GRES Configuration: Add TPU to the general GRES types in your configuration.
    2. Count-based GRES: Use Count-based GRES only. Do not provide File paths for the GRES, as this can cause slurmd to crash on GKE.
    3. Device Access: You must mount the host /dev directory into your containers to allow access to the /dev/vfio/* TPU devices.
  11. Propagate topology from Kubernetes nodes to Slurm nodes

    main

    The slurm-operator can automatically propagate topology information from Kubernetes nodes to Slurm nodes (specifically those running as NodeSet pods).

    To enable this, you must:

    1. Provide a valid Slurm topology.yaml file in your Slurm configuration.
    2. Annotate your Kubernetes nodes with the topology.slinky.slurm.net/spec annotation.

    When a NodeSet pod is scheduled onto an annotated Kubernetes node, the operator reads the annotation and updates the registered Slurm node's topology information. If there is a misconfiguration in either the topology.yaml or the Kubernetes node annotation, the operator will report an error in its logs.