Nomad Autoscaler

repository·main·Indexed 19 days ago

https://github.com/hashicorp/nomad-autoscaler

An extensible daemon for automating scaling in Nomad clusters. It supports horizontal application autoscaling (task groups), horizontal cluster autoscaling (nodes), and dynamic resource sizing for Nomad Enterprise. The tool features a plugin architecture for APM and remote providers, high availability mode via leader election, and readiness override options for managing scaling transitions in spot-heavy or long-drain environments.

Tokens
6.6K
Snippets
19
Records
29
Agent score
65%

What's inside nomad-autoscaler

  1. Overview of Nomad Autoscaler capabilities

    main

    The Nomad Autoscaler is an autoscaling daemon for Nomad designed with a plugin architecture for extensibility. It supports three primary scaling modes:

    1. Horizontal Application Autoscaling: Automatically adjusts the number of task group allocations based on metrics (e.g., CPU, memory, or connection counts) to maintain service-level agreements (SLAs).
    2. Horizontal Cluster Autoscaling: Manages the size of the Nomad cluster by interacting with remote providers to add or remove Nomad clients based on available cluster resources (e.g., free CPU or memory).
    3. Dynamic Application Sizing (Enterprise): Optimizes application resource consumption by analyzing historical usage data to provide CPU and Memory resource recommendations.
  2. Access Nomad Autoscaler nightly builds and Docker images

    main

    For testing the latest features and bug fixes, you can use the nightly release or preview Docker images:

    • Nightly Releases: Binaries built from the latest main branch code are available on the GitHub releases page.
    • Docker Preview Images: Every commit to main generates a preview image available on Docker Hub at hashicorppreview/nomad-autoscaler.
  3. Decide when to use Readiness Override Options

    main

    Choosing whether to enable readiness override options depends on your cluster's priority between stability and responsiveness.

    Use these options when:

    • You run spot-heavy clusters with frequent node replacement events.
    • Your environment has long drain windows (e.g., due to long-running jobs).
    • Your priority is restoring headroom quickly and meeting SLAs over strict stability.

    Do NOT use these options when:

    • You require strict stability and conservative scaling behavior.
    • Capacity accounting accuracy is more important than scaling speed.
    • Your workloads are highly sensitive to short-term over/under scaling during transitions.
  4. Use Readiness Override Options for faster scaling transitions

    main

    The Nomad Autoscaler provides readiness override options that allow scaling flows to proceed even when nodes are in transition states. These options trade strict readiness behavior for increased scaling responsiveness and faster progress during node transitions.

    Supported options:

    • node_filter_ignore_drain: Allows the autoscaler to ignore nodes that are currently being drained.
    • node_filter_ignore_init: Allows the autoscaler to ignore nodes that are in the initialization phase.
    • ignore_asg_events: Allows the autoscaler to ignore Auto Scaling Group (ASG) events during evaluation.

    Risks

    Using these options introduces specific risks:

    • Scaling oscillation: The autoscaler may trigger repeated scaling actions.
    • Capacity inaccuracy: You may experience temporary capacity overshoot or undershoot while transitions are converging.
    • Reduced accuracy: The assumption of a "stable cluster" during evaluation windows becomes less accurate.
  5. Enable High Availability (HA) mode

    main

    To run multiple instances of the autoscaler in HA mode, use the -high-availability-enabled flag. This triggers leader election using a lock in Nomad. All instances must use the same lock-namespace, lock-path, lock-ttl, and lock-delay to participate in the same election.

    nomad-autoscaler agent -high-availability-enabled -high-availability-lock-path="/autoscaler/lock" -high-availability-lock-namespace="default"
  6. Implement the Base plugin interface

    main

    To create a custom plugin for the Nomad Autoscaler, you must implement the Base interface provided by the sdk package. The base.pluginServer (an internal gRPC implementation) wraps your implementation of Base to expose it to the Nomad Autoscaler via gRPC.

    Your implementation of Base must satisfy the following methods which are mapped to the gRPC server:

    • PluginInfo() (*sdk.PluginInfo, error): Returns metadata about the plugin, including its Name and PluginType (e.g., sdk.PluginTypeAPM, sdk.PluginTypeStrategy, or sdk.PluginTypeTarget).
    • SetConfig(config map[string]interface{}) error: Receives the configuration provided by the Nomad Autoscaler and applies it to the plugin.
  7. Run the Nomad Autoscaler agent

    main

    The nomad-autoscaler agent command starts the Autoscaler agent and runs until an interrupt is received. Configuration is primarily managed via config files, but can be partially overridden using CLI arguments or environment variables.

    Usage:

    nomad-autoscaler agent [options] [args]
    nomad-autoscaler agent -config=/path/to/config.hcl