Add nix-snapshotter support to the embedded containerd#9319
Add nix-snapshotter support to the embedded containerd#9319hinshun wants to merge 1 commit intok3s-io:masterfrom
Conversation
|
This is interesting; can you describe in more detail how it might be useful, and when it can be used? See the eStargz documentation for an example of what sort of info we might be looking for before adding another snapshotter. |
|
Nix is a package manager / build system that has a complete understanding of build & runtime inputs for every package. Nix packages are stored in a global hashed path like: Runtime dependencies down to If you inspect its ELF data, you can indeed see its linked against that specific glibc: $ readelf -d /nix/store/s66mzxpvicwk07gjbjfw9izjfa797vsw-hello-2.12.1/bin/hello | grep runpath
0x000000000000001d (RUNPATH) Library runpath: [/nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib]This means that a root filesystem containing that closure is sufficient to run Kubernetes is a great orchestration engine for minimal Nix images, but the current mechanism of building Nix-based image need to compress Nix packages into Docker layer tarballs. There are some heuristics to split Nix packages across layers to improve deduplication but because overlayfs has a 128 layer limit there's bound to be layers containing multiple Nix packages. Nix-snapshotter is a containerd snapshotter that natively understands Nix packages. It also provides a client-side library to build special OCI images with tiny layers that contain the Nix package closure in the For teams that deploy to both bare metal & Kubernetes, this is a huge boon to maintain a single stack and the overhead of containerization is just a few kilobytes of metadata (in the OCI manifest). Most teams using Nix already upload all their artifacts to a binary cache or S3, but also have to re-upload essentially the same data to a Docker registry backend. Lastly, since When using See the README and architecture docs for more details. There is also a HackerNews discussion. |
|
@brandond We have it working end-to-end now in a qemu VM with k3s built with our patches. It did require also forking For example in k3s master, we're currently pinned on Since this can happen asynchronously, wanted to bring up early that we need these two cherry picks into
|
|
Are those patches in containerd v1.7.13? If so we can look at updating to that for the March releases. |
e708b47 to
337292a
Compare
It's been merged for a while now but looks like it's only been cherry-picked to |
337292a to
0a7b227
Compare
|
Ah. I'm not sure when exactly we'll go to 2.0. |
I've started an issue in containerd to see if we can get it cherry-picked to In the mean time, we can maintain our patches for NixOS. |
|
@brandond I've managed to cherry-pick those changes into the next containerd |
|
@hinshun Are you still working on this at all? |
|
Hi @dereknola! It's been a while but it looks like k3s finally picked up my patches to containerd so this work is now unblocked. Will be working on this. |
Signed-off-by: Edgar Lee <edgarhinshunlee@gmail.com>
0a7b227 to
ab340f4
Compare
|
Closing PR as stale, feel free to resubmit or reopen it at a later date. |
Add the nix-snapshotter plugin to k3s's embedded containerd, enabling rootless k3s with nix-snapshotter. This follows the same integration pattern as the existing stargz snapshotter. Changes: - Register nix-snapshotter plugin via blank import in builtins_linux.go - Add NixSupported() validation functions for linux and windows - Add "nix" case to snapshotter switch with image service socket config - Add nix snapshotter containerd config blocks in v2 and v3 templates - Set disable_snapshot_annotations = false for nix (required for layer annotations used by nix-snapshotter) Usage: k3s server --snapshotter=nix Revives k3s-io#9319. Co-Authored-By: Joshua Perry <josh@6bit.com>
Add the nix-snapshotter plugin to k3s's embedded containerd, enabling rootless k3s with nix-snapshotter. This follows the same integration pattern as the existing stargz snapshotter. Changes: - Register nix-snapshotter plugin via blank import in builtins_linux.go - Add NixSupported() validation functions for linux and windows - Add "nix" case to snapshotter switch with image service socket config - Add nix snapshotter containerd config blocks in v2 and v3 templates - Set disable_snapshot_annotations = false for nix (required for layer annotations used by nix-snapshotter) Usage: k3s server --snapshotter=nix Revives k3s-io#9319. Co-Authored-By: Joshua Perry <josh@6bit.com>
Add the nix-snapshotter plugin to k3s's embedded containerd, enabling rootless k3s with nix-snapshotter. This follows the same integration pattern as the existing stargz snapshotter. Changes: - Register nix-snapshotter plugin via blank import in builtins_linux.go - Add NixSupported() validation functions for linux and windows - Add "nix" case to snapshotter switch with image service socket config - Add nix snapshotter containerd config blocks in v2 and v3 templates - Set disable_snapshot_annotations = false for nix (required for layer annotations used by nix-snapshotter) Usage: k3s server --snapshotter=nix Revives k3s-io#9319. Signed-off-by: Ada <ada@6bit.com> Signed-off-by: Joshua Perry <josh@6bit.com> Co-Authored-By: Joshua Perry <josh@6bit.com>
Add the nix-snapshotter plugin to k3s's embedded containerd, enabling rootless k3s with nix-snapshotter. This follows the same integration pattern as the existing stargz snapshotter. Changes: - Register nix-snapshotter plugin via blank import in builtins_linux.go - Add NixSupported() validation functions for linux and windows - Add "nix" case to snapshotter switch with image service socket config - Add nix snapshotter containerd config blocks in v2 and v3 templates - Set disable_snapshot_annotations = false for nix (required for layer annotations used by nix-snapshotter) Usage: k3s server --snapshotter=nix Revives k3s-io#9319. Signed-off-by: Ada <ada@6bit.com> Signed-off-by: Joshua Perry <josh@6bit.com> Co-Authored-By: Joshua Perry <josh@6bit.com>
Proposed Changes
Types of Changes
nix-snapshotteras a go dependencynixas a valid snapshotter option for the agentnixsnapshotter, also use it as an image serviceVerification
Dockerfileto copy the k3s binary to thenixos/nixdocker image, to enable quick verification of k3s + nix-snapshotterTesting
User-Facing Change
Further Comments
Currently still work-in-progress, but wanted to start the conversation whether k3s has the appetite for including
nixsupport. As noted in #9309, in rootless mode the only way is to use the embedded containerd, so rootless k3s + nix-snapshotter is only possible via a contribution.See this for an exciting feature of nix-snapshotter as an image service that enables fully declarative pods (down to the contents of the container image). An image like
nix:0/nix/store/f8b1hia3hcqwa5d46anzy3cszi3s6ybk-nix-image-redis.taris resolved by nix-snapshotter, which is a merkle hash of the Nix packages that make up the image tarball.