Skip to content

🐞 Containers launched by Dagger ignore DaemonSet resource limits #10813

Closed

Description

@fixeasy

What is the issue?

Description
I'm deploying Dagger as a DaemonSet on a Kubernetes cluster, and I've set CPU and memory limits on the dagger-engine pods. However, the containers launched by Dagger (dagger core container from ...) do not inherit these resource constraints, and can consume significantly more memory than specified.

Dagger version

dagger v0.18.12 (unix:///run/dagger/engine.sock) linux/amd64

Steps to reproduce

Setup

  • Dagger version: v0.18.12
  • Kubernetes AKS version: 1.31.5
  • Deployment method: DaemonSet

Resource constraints applied to the DaemonSet

resources:
  limits:
    cpu: "500m"
    memory: "2Gi"
  requests:
    cpu: "100m"
    memory: "1Gi"

Reproduction steps

  1. Deploy dagger-engine as a DaemonSet with the resource limits above.
  2. Use Dagger to launch a container with high memory usage:
dagger core container from --address=<my-registry>/alpine:latest \
  with-exec --args sh --args -c --args "apk add --no-cache stress-ng && stress-ng --vm 1 --vm-bytes 18G --vm-keep --timeout 340s"
  1. Monitor memory usage at both container and node level (via Azure Monitor or kubectl top node).
  2. Observe that the container consumes up to 18 GiB of memory, even though the parent Dagger pod is limited to 2 GiB.

Expected behavior
Containers launched by dagger-engine should either:

  • Inherit the resource limits defined on the pod
  • Fail if they attempt to exceed them

Actual behavior

  • The launched container bypasses the pod's memory limit and consumes up to 18 GiB.
  • The dagger-engine pod continues running until the node's OOM killer steps in.
  • Kubernetes metrics and cgroup tracking do not reflect this container’s usage correctly.

Analysis / Hypothesis
This may be explained by how Dagger (via the BuildKit SDK) spawns containers using runc directly, outside of the Kubernetes container lifecycle:

  • These containers are not visible to the Kubelet, which means Kubernetes cannot monitor or enforce resource usage.
  • Since runc is used to start containers outside of containerd, the resulting containers do not share the same cgroup hierarchy as the parent pod.
  • Consequently, resource limits applied at the pod level are bypassed, and the container runs unconstrained on the node.

Questions

  • Is there a supported or recommended way to propagate Kubernetes resource limits to containers launched by Dagger from within a pod?
  • Could this be addressed in Dagger’s runtime or BuildKit’s container handling logic?
  • Would it make sense to allow users to define resource limits explicitly when using dagger core container?

Log output

No response

Activity

  1. fixeasy commented on Jul 29, 2025

    @fixeasy
    ContributorAuthor

    Additional investigation on cgroups for containers launched by Dagger

    I ran a container inside Dagger and inspected its cgroup settings from within the container.
    Here’s the result when inspecting /sys/fs/cgroup/

    / # ls /sys/fs/cgroup/buildkit/<containerID>/
    cgroup.controllers        cgroup.max.descendants    cgroup.type               cpu.stat                  cpuset.cpus.partition     ... [truncated for brevity]
    / # cat /sys/fs/cgroup/buildkit/<containerID>/cpu.max
    max 100000

    As you can see, the cpu.max file reports:

    max 100000
    

    This indicates that no CPU limit is applied (max means unlimited in cgroups v2).

    This confirms that the container launched by Dagger (via BuildKit) is placed in its own cgroup under /sys/fs/cgroup/buildkit/ and is not subject to the resource constraints defined on the parent dagger-engine pod.

    Since the Kubernetes kubelet doesn’t manage or see this container (as it was launched via runc directly, outside of containerd or the CRI), it cannot enforce the limits or include it in its metrics.

  2. jedevc commented on Jul 30, 2025

    @jedevc
  3. jedevc commented on Jul 30, 2025

    @jedevc
    Contributor

    Okay, I actually cannot repro this.

    My setup:

    • Docker container running dagger (with docker run --memory=2G --rm --name=testing --privileged localhost/dagger-engine.dev:latest)
    • Client connected (using _EXPERIMENTAL_DAGGER_RUNNER_HOST="docker-container://testing")

    I can see the cgroups being correctly configured.

    $ cat /sys/fs/cgroup/system.slice/docker-$(docker inspect testing --format={{.ID}}).scope/memory.max
    2147483648
    $ cat /sys/fs/cgroup/system.slice/docker-$(docker inspect testing --format={{.ID}}).scope/buildkit/memory.max
    max
    $ cat /sys/fs/cgroup/system.slice/docker-$(docker inspect testing --format={{.ID}}).scope/buildkit/<namespace-id>/memory.max
    max
    

    Because cgroups are hierarchical, we inherit the limit of 2147483648. Using the same stress-ng tool, and monitoring <namespace-id>/memory.current, I see it never exceeds 2147483648.

    I can also easily trigger an OOM:

    $ _EXPERIMENTAL_DAGGER_RUNNER_HOST="docker-container://testing" dagger -M shell -c "container | from alpine | with-exec -- sh -c 'cat /dev/zero | head -c 4147483648 | tail > /dev/null'"
    tail: out of memory
    

    From the root of your node, can you confirm the entire cgroup hierarchy, not only from within the dagger container? I'm wondering if perhaps the limits are not being correctly applied.

  4. fixeasy commented on Jul 30, 2025

    @fixeasy
    ContributorAuthor

    Thanks for the quick response !

    You're right — in your local Docker setup the containers launched via BuildKit inherit cgroup limits correctly. But in my case, I'm running Dagger as a DaemonSet on AKS (Azure Kubernetes Service), and I’m seeing different behavior.

    Cluster context

    On AKS, container cgroups are managed under:

    /sys/fs/cgroup/kubepods.slice/
    

    This includes:

    • kubepods-besteffort.slice
    • kubepods-burstable.slice
    • kubepods.slice
      → Which reflect Kubernetes QoS classes.

    For example, my Dagger dagger-engine pod is running here:

    /sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod<POD_UID>.slice/cri-containerd-<CONTAINER_ID>.scope
    

    And as expected:

    # cat memory.max
    2147483648

    Which corresponds to my Kubernetes resource limits:

    resources:
      limits:
        cpu: "500m"
        memory: "2Gi"
      requests:
        cpu: "100m"
        memory: "1Gi"

    BuildKit containers ignore cgroup limits

    However, the containers spawned by Dagger (via BuildKit) end up in a different cgroup hierarchy:

    /sys/fs/cgroup/buildkit/<CONTAINER_ID>/

    And when inspecting the limits:

    # cat /sys/fs/cgroup/buildkit/<CONTAINER_ID>/memory.max
    max
    # cat /sys/fs/cgroup/buildkit/memory.max
    max

    ➡️ No limit is applied.

    These BuildKit containers are not children of the dagger-engine pod's cgroup, and therefore they bypass the resource controls enforced by the kubelet.

    Hypothesis

    This could be because:

    • Dagger (via BuildKit) uses runc directly to start containers.
    • Since they are not launched through containerd + CRI, Kubernetes doesn't see them, and doesn’t apply cgroup parenting or limits.
    • As a result, these containers run unconstrained at the node level, leading to potential OOMs.
  5. jedevc commented on Jul 30, 2025

    @jedevc
    Contributor

    Can you definitely confirm that these are in different hierarchys?

    Namespaces make this trickier: https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html

    Two cgroups can be part of the same hierarchy and still appear to be isolated based on cgroup namespaces established.

    Can you please share the results of:

    $ tree /sys/fs/cgroup
    

    from the top-level node. This should confirm the exact layout of the cgroups, it's still not actually clear to me that you're actually looking at two different hierarchys.

    If they actually are two different hierarchy, and the behavior you're describing is correct, I suspect there's something to do with the AKS environment you're in somehow not adequately isolating cgroup namespaces.

  6. jedevc commented on Jul 30, 2025

    @jedevc
    Contributor

    I don't easily have an AKS environment ready to test this in btw - if there's any way you can construct a local reproducer using docker or k3s or minikube or something like that, it'll be significantly easier to properly dig into.

  7. marcosnils commented on Jul 30, 2025

    @marcosnils
    Contributor

    @jedevc @fixeasy I was able to repro this using kind. Steps to repro:

    1. Create a kind cluster with kind create cluster. Single node should be enough
    2. Deploy the dagger helm chart as described here: https://docs.dagger.io/ci/integrations/kubernetes/#example
    3. Verify the engine cgroup hierarchy with cat /proc/$engine_pid/cgroup. In my case, the engine showed something like: 0::/system.slice/docker-7317024ce3f45469e0d9461261c329f7a3daa1d7f055bbaa8ff2200c1ecbcf96.scope/kubelet.slice/kubelet-kubepods.slice/kubelet-kubepods-besteffort.slice/kubelet-kubepods-besteffort-podc47ba076_1ae8 _4860_b49b_5e9db3cc6660.slice/cri-containerd-3e5a7e7748cf8eb039487290cb0fc84ed50145bbf1ddfc6906c7a3b7fdcad4f7.scope
    4. Run a container in that engine and check its cgroup hierarchy. I'm getting something like this: 0::/system.slice/docker-7317024ce3f45469e0d9461261c329f7a3daa1d7f055bbaa8ff2200c1ecbcf96.scope/buildkit/jnkv5ry38lwhm8imctwpfutrr

    As you can see, it doesn't seem to he honoring the Kube pod hierarchy as the OP described.

  8. fixeasy commented on Aug 18, 2025

    @fixeasy
    ContributorAuthor

    @jedevc
    Gentle ping 🙂 any chance you could reproduce it with kind like @marcosnils did?

  9. gregoryboue commented on Feb 12, 2026

    @gregoryboue

    @jedevc @marcosnils is there any news on this subject ?

  10. locked and limited conversation to collaborators on Mar 25, 2026
  11. converted this issue into a discussion #12703 on Mar 25, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions