kaniko icon indicating copy to clipboard operation
kaniko copied to clipboard

How to solve the disk space exceeds problem

Open Sodawyx opened this issue 6 months ago • 2 comments

I used Kaniko in cloud environment and the root execution environment / only supports 10GB. The base image of dockerfile is almost 30GB. When image building, Kaniko will unpacking rootfs, and the disk size exceeds. I mount a volume to /mnt/dir, how to unpacking rootfs to /mnt/dir, or any other solutions? The sample docker file is as follow.

FROM qwen:latest
ADD ./test /

Sodawyx avatar May 29 '25 11:05 Sodawyx

I don't think this will work with kaniko. The main selling point of kaniko is that it doesn't need any privileges to run. To the outside world it's just a regular program that moves a few files around, nothing suspicious going on. But that also gives three important constraints on how kaniko can be used:

  • our build context is the executor image itself - modifying the kaniko image will most likely break it
  • kaniko will never be able to build two stages in parallel - as there is only one context to go around
  • and finally kaniko will not be able to build outside the rootdir as this is our build-context by definition

There might be some tricks that would bring the latter to work via chroot but at that point you're back at requiring privileges again if I'm not mistaken. Maybe your problem can be solved differently, either by reducing the size of the image, I can recommend to have a look at it using dive. Or find a way to increase the size of the root partition.

note I'm not a kaniko maintainer, so thinks might work that I'm not aware of. This is just my point of view as a user. If you need help with investigating alternatives I'm happy to help you can find me on slack https://kubernetes.slack.com/archives/D04AU8E0JP6

mzihlmann avatar May 29 '25 15:05 mzihlmann

One thing you could try is investigate which files in the image are large. If you manage to mount the volume into both where kaniko downloads the image-layers to and also into where the large files later get copied into, you might get away with it.

mzihlmann avatar May 29 '25 15:05 mzihlmann