# A single-node k3s server for a NixOS VM test: import it as a node module, # `imports = [ (import ./lib/k3s-node.nix { images = [ … ]; }) ]`. # # - `images`: `dockerTools` image tarballs (`buildLayeredImage`), which k3s' # containerd imports from its image directory at start. Nothing is pulled: # the VM has no network, so a pod names one of these with # `imagePullPolicy: Never`. `/etc/k3s-node/images` lists their references # (`imageName:imageTag`, one per line) for `lib/k3s.py`'s `wait_images`. # - `memoryMiB`: the VM's memory. # # CoreDNS and the local-path provisioner stay on, so a test can use cluster DNS # and PersistentVolumeClaims. The firewall stays on and trusts the pod network's # interfaces, so the node reaches pods on their IPs. # # `lib/k3s.py` holds the Python helpers a test script uses with this node. { images ? [ ], memoryMiB ? 6144, }: { config, pkgs, ... }: { services.k3s = { enable = true; role = "server"; images = [ config.services.k3s.package.airgap-images ] ++ images; extraFlags = [ "--disable=traefik,servicelb,metrics-server" "--write-kubeconfig-mode=644" ]; }; environment.systemPackages = [ pkgs.kubectl pkgs.curl ]; environment.variables.KUBECONFIG = "/etc/rancher/k3s/k3s.yaml"; environment.etc."k3s-node/images".text = pkgs.lib.concatMapStrings ( i: "${i.imageName}:${i.imageTag}\n" ) images; networking.firewall.trustedInterfaces = [ "cni0" "flannel.1" ]; virtualisation = { memorySize = memoryMiB; cores = 4; diskSize = 8192; }; }