Repository navigation
Closed
Description
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
- Deploy dagger-engine as a DaemonSet with the resource limits above.
- 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"- Monitor memory usage at both container and node level (via Azure Monitor or kubectl top node).
- 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
Reacted by Mehdi Kadar, Daniel Wegener, Victor Mikolajczyk, Sunny au support, gregoryboue and Andy Lo-A-Foe
Metadata
Metadata
Assignees
Labels
No labels
Activity
fixeasy commentedon Jul 29, 2025
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/As you can see, the
cpu.maxfile reports:This indicates that no CPU limit is applied (
maxmeans 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 parentdagger-enginepod.Since the Kubernetes
kubeletdoesn’t manage or see this container (as it was launched viaruncdirectly, outside of containerd or the CRI), it cannot enforce the limits or include it in its metrics.jedevc commentedon Jul 30, 2025
jedevc commentedon Jul 30, 2025
Okay, I actually cannot repro this.
My setup:
docker run --memory=2G --rm --name=testing --privileged localhost/dagger-engine.dev:latest)_EXPERIMENTAL_DAGGER_RUNNER_HOST="docker-container://testing")I can see the cgroups being correctly configured.
Because cgroups are hierarchical, we inherit the limit of
2147483648. Using the samestress-ngtool, and monitoring<namespace-id>/memory.current, I see it never exceeds2147483648.I can also easily trigger an OOM:
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.
fixeasy commentedon Jul 30, 2025
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
DaemonSeton AKS (Azure Kubernetes Service), and I’m seeing different behavior.Cluster context
On AKS, container cgroups are managed under:
This includes:
kubepods-besteffort.slicekubepods-burstable.slicekubepods.slice→ Which reflect Kubernetes QoS classes.
For example, my Dagger
dagger-enginepod is running here:And as expected:
# cat memory.max 2147483648Which corresponds to my Kubernetes resource limits:
BuildKit containers ignore cgroup limits
However, the containers spawned by Dagger (via BuildKit) end up in a different cgroup hierarchy:
And when inspecting the limits:
➡️ 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:
runcdirectly to start containers.jedevc commentedon Jul 30, 2025
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:
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.
jedevc commentedon Jul 30, 2025
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
dockerork3sorminikubeor something like that, it'll be significantly easier to properly dig into.marcosnils commentedon Jul 30, 2025
@jedevc @fixeasy I was able to repro this using
kind. Steps to repro:kind create cluster. Single node should be enoughcat /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.scope0::/system.slice/docker-7317024ce3f45469e0d9461261c329f7a3daa1d7f055bbaa8ff2200c1ecbcf96.scope/buildkit/jnkv5ry38lwhm8imctwpfutrrAs you can see, it doesn't seem to he honoring the Kube pod hierarchy as the OP described.
fixeasy commentedon Aug 18, 2025
@jedevc
Gentle ping 🙂 any chance you could reproduce it with kind like @marcosnils did?
gregoryboue commentedon Feb 12, 2026
@jedevc @marcosnils is there any news on this subject ?