WARNING! Using Docker-in-Docker (privileged containers) in Kubernetes is a major security risk. Safer alternatives include BuildKit (rootless mode) and Buildah.
Summary
Kubernetes cloud agents, especially those using Docker-in-Docker (DinD), can consume large amounts of disk space during builds. The main areas to manage are:
- Docker storage, for example
/var/lib/docker - TeamCity checkout/work directory, for example
/opt/buildagent/work - TeamCity agent
tempDirandsystemDir
Docker storage is managed by Docker/container runtime. TeamCity manages its own agent directories and checkout cleanup.
Recommendation
Avoid placing large build-related paths on the shared Kubernetes node root disk.
Where possible, use dedicated storage for:
- TeamCity agent data
workDirtempDirsystemDir
- Docker data
/var/lib/docker
This helps isolate disk usage and reduces the risk of node-level disk pressure or pod eviction.
TeamCity Work Directory Cleanup
TeamCity checkout directories are kept for reuse and expire after 192 hours / 8 days by default.
This can be adjusted with:
teamcity.agent.build.checkoutDir.expireHours=<hours>
or:
system.teamcity.build.checkoutDir.expireHours=<hours>
For busy or short-lived Kubernetes agents, consider reducing this value, for example:
system.teamcity.build.checkoutDir.expireHours=24
Use 0 only when clean checkout after each build is acceptable, as this may increase build time.
Free Disk Space Feature
Use the Free Disk Space build feature to check and clean TeamCity-managed disk usage before the build and before source checkout/build preparation.
Main property:
system.teamcity.agent.ensure.free.space=<size>
Temp-specific property:
system.teamcity.agent.ensure.free.temp.space=<size>
Free Disk Space checks the actual filesystem/volume for each path:
workDir -> checked on the volume where workDir resides
tempDir -> checked on the volume where tempDir resides
systemDir -> checked on the volume where systemDir resides
There is no separate documented threshold property specifically for systemDir.
Docker / DinD Storage
For DinD agents, place /var/lib/docker on a dedicated volume where possible.
TeamCity does not fully manage Docker image/layer retention. Use Docker/BuildKit cleanup, registry-backed cache, short-lived pods, or capped volumes to control Docker storage growth.
Key Takeaway
Use TeamCity features for TeamCity-managed directories.
Use Kubernetes/Docker controls for Docker-managed storage.
Do not rely on the Kubernetes node root disk for large checkout, cache, or Docker write paths.
For additional details:
Comments
0 comments
Please sign in to leave a comment.