Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active October 4, 2023 19:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lalyos/02fd3b75fc0152a334a5298286164741 to your computer and use it in GitHub Desktop.
k3s with airgap image prewarmed
mkdir -p /var/lib/rancher/k3s/agent/images/
VERSION_K3S=$(curl -w '%{url_effective}' -L -s -S https://update.k3s.io/v1-release/channels/stable -o /dev/null | sed -e 's|.*/||')
curl -sL -o /var/lib/rancher/k3s/agent/images/airgap-images.tar https://github.com/k3s-io/k3s/releases/download/${VERSION_K3S}/k3s-airgap-images-amd64.tar

Install k3s

Usually k3s is installed with a shell script:

curl -sL get.k3s.io | sh

This will download the k3s binary create a systemd service and start it. Start time includes the download of system images:

  • docker.io/rancher/klipper-helm
  • docker.io/rancher/mirrored-library-traefik
  • docker.io/rancher/mirrored-metrics-server
  • docker.io/rancher/mirrored-coredns-coredns
  • docker.io/rancher/local-path-provisioner
  • docker.io/rancher/klipper-lb
  • docker.io/rancher/mirrored-library-busybox
  • docker.io/rancher/mirrored-pause

Spedup startup by pre-downloading images

To speed-up startup time, you can pre download images (make part of your vm/docker image) with the 3 lines above: [00-k3s-airgap-images.sh]

Additional images

Lets say you want to add nginx golang and alpine to the prewarmed images, you can use crane to download images:

# install crane
curl -sL https://github.com/google/go-containerregistry/releases/download/v0.16.1/go-containerregistry_Linux_x86_64.tar.gz | tar -xz -C /usr/local/bin/ crane

download images
for img in alpine nginx:alpine golang:alpine; do 
  crane pull ${img} /var/lib/rancher/k3s/agent/images/${img}.tar
done

Reference

tl;dr

to figure put the system image names you can start up k3s and after 1 minute or so:

kubectl  get no -o jsonpath='{range .items[0].status.images[*].names[0]}{$}{"\n"}{end}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment