NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.69k stars 13.14k forks source link

Package request: k0s #247158

Open TECHNOFAB11 opened 11 months ago

TECHNOFAB11 commented 11 months ago

Project description

"k0s - The Zero Friction Kubernetes" Combines multiple components of Kubernetes into a single small binary.

Metadata

I quickly tried to package it using buildGoModule but this seems to be more complicated than that (they use docker and extremely hard to read Makefiles to build) because a simple go build . fails aswell. Not sure if it's a good idea to just create a derivation which calls make as this needs docker etc. which isn't quite the nix way :D Ideas welcome :)

johbo commented 11 months ago

Just wanted to try out k0s on a spare NixOS system of mine, realized that the imperative installation method is not working because k0s install tries to write into /etc/systemd/system/k0scontroller.service.

I got it to start with the following unit configuration injected via my configuration.nix:

  systemd.services.k0scontroller = {
    description = "k0s - Zero Friction Kubernetes";
    documentation = [ "https://docs.k0sproject.io" ];
    path = with pkgs; [
      # It wants to use "modprobe" to load kernel modules
      kmod
      # Using "mount"
      util-linux
    ];
    after = [ "network-online.target" ];
    wants = [ "network-online.target" ];
    wantedBy = [ "multi-user.target" ];
    startLimitIntervalSec = 5;
    startLimitBurst = 10;
    serviceConfig = {
      RestartSec = 120;
      Delegate = "yes";
      KillMode = "process";
      LimitCORE = "infinity";
      TasksMax = "infinity";
      TimeoutStartSec = 0;
      LimitNOFILE = 999999;
      Restart = "always";
      ExecStart = "/usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --data-dir=/var/lib/k0s --single=true";
    };
    unitConfig = {
      ConditionFileIsExecutable = "/usr/local/bin/k0s";
    };
  };
TECHNOFAB11 commented 11 months ago

I actually managed to at least build k0s: https://gitlab.com/TECHNOFAB/nix-packages/-/blob/main/pkgs/k0s/default.nix It's not very nice because I had to give it pkgs.kubernetes and I'm not sure if thats optimal. Wasn't able to get it working yet though, though downloading k0s and using that didn't work either, so I might have done something wrong. If anyone wants to test feel free to use my derivation (saying cuz there's no license in that repo)

usmcamp0811 commented 10 months ago

using the above derivations I was able to get my node to join the cluster but am running into CNI issues trying to get Flannel working... I think. I installed cni-plugin-flannel and I'm going down that path to see what I need to do..

EDIT: I figured out the problem it was a PATH issue. I did this and things started working:

    systemd.services.k0sworker = {
      description = "k0s - Zero Friction Kubernetes";
      documentation = [ "https://docs.k0sproject.io" ];
      after = [ "network-online.target" ];
      wants = [ "network-online.target" ];
      serviceConfig = {
        ExecStart = "${pkgs.campground.k0s}/bin/k0s worker --token-file=/config/workertoken";
        Restart = "always";
        Environment = "PATH=/run/wrappers/bin/:$PATH";  # Add this line

      };
      wantedBy = [ "multi-user.target" ];
    };

my config is located here. I'm still cleaning up and see if there is anything else that was actually required..

nxy7 commented 10 months ago

It might not be very helpful, but it can maybe be easier to try using k0s with cilium (installed via helm) as CNI and kube-proxy replacement, just to make sure that everything else is working correctly.

johbo commented 6 months ago

I've started a small Nix Flake on this based on the work of the other collaborators of this PR. It contains the proposed binary packaging and a start of a NixOS module.

https://github.com/johbo/k0s-nix