Docker K8s optimize images to reduce load time

2/10/2020

We have a lot docker images that we need to upload to k8s, it works however when we start a new node this process can take a lot of time.

We try to change the images to use "multi-stage" builds however still this process take a lot of time and we didn't saw significant change on the start time on new node.

Now we try the following: (however we not sure how much impact we will see ...)

  1. Try (as much as we can) to use the same docker images from , example all the images which use alpine to use the exact same version (3.11) and not some of using version 3.10 and some 3.10.1 and some 3.11 etc , this will prevent the reuse mechanism of docker to layers that already cashed ...

  2. Reduce the layers numbers , with combining the RUN commands to one instead of many.(we need to do it for many docker files...) , not sure how docker mechanism will help here to achieve our goals

All this process to change both of using the same version and reduce layers can take a lot of time to do, are we are wasting our time or there or this is something that can reduce the load time ? is there any other idea which may help us ?

We have many docker images based on Golang, NodeJS, java, etc.

-- Beno Odr
amazon-web-services
docker
kubernetes
linux

1 Answer

2/10/2020

so you are on the correct track

  • use minimum layer
  • reuse layers
  • use same from tag to cache layers
  • use alpine or slim images
  • use multi-stage build

I think you can not reduce size further. Just try docker squash but this will not help much.

So how you can boot your nodes faster?

  • is it possible to bake node image with the required image layers inside it?
  • is it possible to set up a docker registry next to your nodes? so that it will pull image faster without network lags
  • is it possible to keep libraries outside image and mount libraries at runtime? (eg. if your code is nodejs code, keep npm's outside of the container and mount npms directory at runtime)
  • k8s can run other than docker images. like cri-o. is it possible for you to build cri-o images? they are lightweight.
-- Guru
Source: StackOverflow