Skip to content

feat(k8s): place the runner Jobs on a node that fits their memory limit #5485

Not planned

Description

@dan-petty

Update 2026-11-26 (infra move): The node label belongs to dan-petty/homelab.

This item keeps the runner affinity and its checks in k8s/devops/. The label is the homelab follow-up and must exist first. docs/K8S_PERFORMANCE.md is now docs/guidelines/kubernetes.md, which has no query Q10 or target T14. dan-petty/homelab#13 is closed.

Follow-up: dan-petty/homelab#302.


Problem or Motivation

In the 7 days to 2026-11-13, 47 of 47 runner pods ran on <control-plane-node>. The runner Job template (k8s/devops/cronjob-runner.yaml) sets no node selector and no affinity. The default scheduler prefers the node with the most free resources (LeastAllocated), and <control-plane-node> has 48 CPUs, so it takes every Job.

That node also runs the k3s server. It reserves no memory for the system and has no memory eviction threshold (dan-petty/homelab#13). The memory limit of a runner Job is 16Gi above a request of 2Gi or 6Gi, and the scheduler places a pod by its request only. So:

  • A runner Job that bursts takes memory from the k3s server.
  • When <parked-node> (12.8 GiB allocatable) is uncordoned (#5143), a Job with a 6Gi request can go there and burst past the memory of the node.

Proposed Solution & Architectural Design

  1. Keep each runner Job on a node whose allocatable memory is at or above roadmap.implement.max_memory_limit. Use a standard control: a node label that the node-provisioning automation sets on such nodes and a required node affinity (or nodeSelector) in the Job template, or a taint on the small node.
  2. Prefer the GPU workers to <control-plane-node> with a preferred node affinity on the label node-role.kubernetes.io/control-plane. Do this after dan-petty/homelab#13 gives the node a memory reserve, and measure the effect with the tuning loop of docs/K8S_PERFORMANCE.md.
  3. Check that the admission policy roadmap-service-jobs admits the new fields. It does not pin nodeSelector and tolerations today.

Acceptance Criteria

  • A test proves that the runner Job that the Service builds holds the placement rule, and that the admission policy admits it.
  • Live proof after the merge: query Q10 of docs/K8S_PERFORMANCE.md shows no runner pod on a node with less allocatable memory than the limit, and shows the runner pods on the workers while a worker has room, over 7 days.

Target Subsystem

Kubernetes (k8s/devops/cronjob-runner.yaml, k8s/devops/roadmap-service/admissionpolicy.yaml, src/devops_cli/roadmap/implement/).

Existing Tool Considered

Kubernetes node affinity, node labels and taints cover the need. No new tool. Cost to build (estimate): 150,000 tokens and 2 hours.

Related

docs/K8S_PERFORMANCE.md (#5444), target T14 and gap "Every runner Job runs on the control-plane node". #5013 (PriorityClass), dan-petty/homelab#13 (kubelet reserve and eviction).

Source: #5444

Alternatives check of 2026-11-23: in-use.
The repository already uses this tool.
Tool: kubernetes/kubernetes (https://github.com/kubernetes/kubernetes), Apache-2.0, last activity 2026-11-21, maintained.
Reason: Searches found no other tool that fits pods to a node's memory; the scheduler's required node affinity, node labels and taints cover the whole placement need, and the issue names them as the tool already in use.

Covers:

  • Required node affinity pins each runner Job to labeled nodes
  • Node labels mark nodes whose allocatable memory fits the limit
  • Preferred affinity can steer GPU workers to the control-plane node
  • Taints keep small nodes free of runner Jobs

Lacks:

  • No node is labeled by this repository; the infra repo must set it
  • Scheduler places by request, so the label must track the memory limit
  • No built-in check or query that a live pod landed on a fitting node

Proposed design

Problem statement

Runner Jobs run on the control-plane node. The scheduler prefers the node with the most free resources, and the runner Job template sets no placement rule. The control-plane node also runs the k3s server. A runner Job that bursts can take memory from the server. A small node with 12.8 GiB allocatable cannot hold the memory limit of a Job. The change must keep each runner Job on a node that can hold its memory limit.

Acceptance criteria

Requirement: Runner Job requires a memory-fit node

The runner Job template SHALL set a required node affinity on the node label devops-cli/runner-memory-fit with the operator In and the value true.

Scenario: The k8s gate check accepts the required affinity

  • WHEN uv run devops ci --check --only k8s runs the runner placement check on the Job that CronJob devops-cli-runner makes from k8s/devops/cronjob-runner.yaml
  • THEN The check passes and reports the required node affinity on devops-cli/runner-memory-fit with the operator In and the value true.

Requirement: The Service Job builder keeps the required affinity

The Service Job builder SHALL keep the required node affinity of the template in the runner Job it creates.

Scenario: The builder keeps the required affinity

  • WHEN uv run pytest tests/roadmap/implement/test_runner_placement.py calls the builder with a template that holds the required node affinity on devops-cli/runner-memory-fit
  • THEN The test passes and the Job holds the required node affinity on devops-cli/runner-memory-fit with the operator In and the value true.

Requirement: The placement check rejects a Job without the required affinity

The runner placement check MUST fail when the runner Job template has no required node affinity on devops-cli/runner-memory-fit.

Scenario: The placement check rejects a Job with the required term removed

  • WHEN uv run pytest tests/gate/k8s_checks/test_runner_placement.py runs the placement check on a rendered runner Job with the required term removed
  • THEN The test passes and the placement check raises an error that names the missing required node affinity on devops-cli/runner-memory-fit.

Requirement: The admission policy admits the runner Job

The roadmap-service-jobs admission policy MUST admit the runner Job that the template builds with the required node affinity.

Scenario: The k8s gate check admits the runner Job

  • WHEN uv run devops ci --check --only k8s runs the admission policy check on the Job that CronJob devops-cli-runner makes
  • THEN The check passes and reports that roadmap-service-jobs admits the Job with the required node affinity.

Requirement: Pending a person after the merge

After the merge, the live check SHALL show no runner container on a node with less allocatable memory than the memory limit of that container.

Scenario: The live query returns no runner container over the memory of its node

  • WHEN uv run devops prometheus query 'max by (namespace,pod,node,container) (kube_pod_container_resource_limits{namespace="devops",resource="memory",pod=~"devops-cli-runner-.*"} or kube_pod_init_container_resource_limits{namespace="devops",resource="memory",pod=~"devops-cli-runner-.*"}) > on(node) group_left() max by (node) (kube_node_status_allocatable{resource="memory"})' runs over the last 7 days
  • THEN The query returns no series.

Existing Tool Considered

The alternatives check in the issue body records the verdict in-use for kubernetes/kubernetes (Apache-2.0, last activity 2026-11-21, maintained) on 2026-11-23. The block of that check lists what the tool covers and lacks. This change uses the scheduler's required node affinity in k8s/devops/cronjob-runner.yaml and adds no placement code. The infra repo dan-petty/homelab sets the label in homelab#302, and the proposal records that as the suspected block. The k8s gate check proves the Job holds the rule and the admission policy admits it.

Key questions

  • Which control keeps a runner Job off a node whose allocatable memory is below its memory limit?: Use a required node affinity on the boolean label devops-cli/runner-memory-fit=true. A hard rule keeps a Job whose limit is above its request off a node that cannot hold the limit. A preferred affinity can be ignored. A taint keeps every pod off the small node, not only a runner Job. (best practice) [sources: docs/guidelines/kubernetes.md, k8s/devops/cronjob-runner.yaml]
    • Chosen: Required node affinity on a boolean label. The scheduler enforces it for every Job. The same affinity field can hold the later preferred term.
    • Rejected: Preferred node affinity. The scheduler can ignore it. A Job can still land on a node that cannot hold its limit.
    • Rejected: Taint on the small node. It keeps every pod off the node, not only a runner Job. It needs a change in the infra repo for each small node.
    • Rejected: nodeSelector on the label. It is valid, but the required node affinity keeps the affinity field for the later preferred term and states the operator.
  • Which node label does the required affinity select, and who sets it?: Use the boolean label devops-cli/runner-memory-fit=true. The node-provisioning automation of the infra repo dan-petty/homelab sets it in homelab#302 on each node whose allocatable memory is at or above roadmap.implement.max_memory_limit. A boolean label keeps no second copy of the limit in the manifest. (best practice) [sources: CONTEXT.md, docs/guidelines/kubernetes.md, k8s/devops/cronjob-runner.yaml]
    • Chosen: Boolean label set for the configured maximum. The manifest holds no number that a change of roadmap.implement.max_memory_limit would make stale.
    • Rejected: Integer label with the operator Gt. The threshold in the manifest would be a second copy of the setting.
    • Rejected: Existing node-role.kubernetes.io/control-plane label. It excludes the control-plane node but still admits a small worker node that cannot hold the memory limit.
  • Does the roadmap-service-jobs admission policy admit a runner Job with the new affinity?: Yes. The policy file k8s/devops/roadmap-service/admissionpolicy.yaml does not reference affinity. The gate check builds the Job that the Service makes from the template and runs every expression against it. The policy file needs no change. [sources: k8s/devops/roadmap-service/admissionpolicy.yaml]
  • Does the preferred affinity for GPU workers ship in this change?: No. Defer it. The issue says to do it after the control-plane node gets a memory reserve and to measure the effect. The current change adds only the required memory-fit affinity. (best practice) [sources: docs/guidelines/kubernetes.md]
    • Chosen: Defer the preferred affinity. The step waits on an outside change and a 7-day measurement. The required affinity does not need either.
    • Rejected: Ship the preferred affinity now. It contradicts the order in the issue and cannot be measured at merge time.
    • Rejected: Ship a preferred affinity toward the control-plane node. The issue makes that step wait on the memory reserve.
  • Can the 7-day live proof be an acceptance criterion of this change?: Yes, as a criterion named Pending a person after the merge. A pull request cannot show 7 days of runtime before the merge. The person runs the PromQL query after the merge. The proof uses the tuning loop of docs/guidelines/kubernetes.md. (best practice) [sources: docs/guidelines/kubernetes.md]
    • Chosen: Post-merge live criterion named Pending a person after the merge. The instruction for a post-release live proof gives this form. The query reads cluster history after the merge.
    • Rejected: Defer the live proof to a verification issue. The issue asks for the live proof after the merge, and a criterion can hold the person step.
    • Rejected: Keep the live proof as a pre-merge gate. No command shows 7 days of runtime at merge time.
  • Where must the label exist, and what does this change wait on?: The label must be on each node that may run a runner Job. The node-provisioning automation of the infra repo dan-petty/homelab sets it in homelab#302. No manifest of this repository labels a node. Until the label exists, a runner Job with the required affinity stays Pending. The label must be on the nodes before this change merges. [sources: CONTEXT.md, docs/guidelines/kubernetes.md, k8s/devops/cronjob-runner.yaml]

Fit

Fits in one pull request.

Suspected block

The node label devops-cli/runner-memory-fit=true must exist on each node that may run a runner Job before this change merges; the infra repo dan-petty/homelab sets it in homelab#302, and this repository labels no node.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/feature
    scope/k8s
    status/new
    value/medium
    effort/medium
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 13, 2026
  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The searches returned only scheduler add-ons (kubernetes-sigs/descheduler, kubernetes-sigs/scheduler-plugins) beside the Kubernetes scheduler itself, and the placement rule the issue wants is a core Kubernetes scheduling control that the cluster already runs: a required node affinity or nodeSelector on a node label, plus a preferred affinity toward node-role.kubernetes.io/control-plane, covers the whole need with no new component. The issue already names Kubernetes node affinity, node labels and taints as the tool that covers it, so no additional tool is required.

    The repository already uses this tool.

    Tool: kubernetes/kubernetes (https://github.com/kubernetes/kubernetes)

    • License: Apache-2.0
    • Last activity: 2026-11-17
    • Maintained: yes

    Covers:

    • required node affinity or nodeSelector on a label that the node-provisioning automation sets on nodes whose allocatable memory is at or above the maximum memory limit
    • preferred node affinity on node-role.kubernetes.io/control-plane to steer GPU workers to the control-plane node
    • taints on a small node to keep runner Jobs off it
    • placement is decided by the scheduler at admission from the fields of the Job template, before any burst can take memory from the k3s server

    Lacks:

    • it does not label or taint the nodes itself; the provisioning automation must set the label and keep it in step with each node's allocatable memory
    • the Job template and the roadmap-service-jobs admission policy must be changed by this project to carry and admit the new fields, and the acceptance test and the Q10 live proof remain project work
    • the scheduler still places by request, so the rule relies on the node label rather than on measured memory
    • a placement-only control does not add the kubelet memory reserve or eviction threshold of dan-petty/homelab#13

    Tools considered:

    Searches run:

    • Kubernetes scheduler places pod by request not memory limit tool to keep pod off small node, results: 5
    • Kubernetes node affinity nodeSelector schedule pod onto node with enough allocatable memory, results: 5
    • kubernetes.io assign pods to nodes node affinity, results: 5
    • kubernetes node affinity requiredDuringSchedulingIgnoredDuringExecution documentation, results: 5
    • k3s node label node-role.kubernetes.io/control-plane nodeSelector job template, results: 5
    • kubernetes descheduler, results: 5
    • assigning pods to nodes kubernetes documentation, results: 5
    • kubernetes scheduler plugins Trimaran load aware scheduling, results: 5
    • kubernetes-sigs/scheduler-plugins, results: 5
    • nodeSelector kubernetes, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Owner question: The node label devops-cli/runner-memory-fit must be on each node that may run a runner Job before this template change merges; the node-provisioning automation of the infra repo dan-petty/homelab sets it, and this repository labels no node.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  8. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  9. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  10. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    The node label that this item needs has a pull request: dan-petty/homelab#536 (for dan-petty/homelab#302).

    • The play ansible/playbooks/18_runner_memory_fit.yaml (make runner-memory-fit) sets devops-cli/runner-memory-fit=true on each node whose allocatable memory is at or above roadmap.implement.max_memory_limit of ConfigMap devops/devops-cli-config, and removes it from the other nodes.
    • With the live limit 16Gi, a check-mode plan labels hog, condor, gemini and bombas, and not hawk (allocatable 12320184Ki).
    • Order: dan-petty/homelab#536 merges and a person applies the play before the required node affinity of this item merges. Else each runner Job stays Pending.
    • The play must run again after a change of the limit or of k3s_memory_reserved.
  11. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    Closed as not planned. Owner, 2026-11-27: no custom node label for this. #7422 sets the memory limit of each runner Job equal to its request, so the scheduler keeps a Job off a node that cannot hold it. dan-petty/homelab#302 (the label play) is closed too. Part 2 of this item (protect the k3s server on the control-plane node): after #7422 a Job cannot use more memory than it reserved, so it cannot take memory from the server. The scheduler can still place Jobs on that node; the reserve of the server itself is the kubelet system-reserved setting (dan-petty/homelab#13).

  12. removed
    status/new
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions