Skip to main content

Kubernetes: Introduction

Kubernetes - This article is part of a series.
Part 1: This Article

Introduction
#

This documentation follows on from my NixOS documentation and describes the creation of a single node k3s cluster using nix. A mixture of helm and raw manifests will be used but all will be defined in pure nix as part of my nix-config flake.

Enabling k3s
#

To begin using Kubernetes on NixOS we can enable the k3s service along with a token secret:

{
  inputs,
  ...
}:
{
  flake.modules.nixos.k3s =
    {
      config,
      lib,
      pkgs,
      ...
    }:
    {
      options = {
        k3s.enable = lib.mkEnableOption "k3s";
        secrets.k3s.enable = lib.mkEnableOption "k3s token secret";
      };

      config = lib.mkMerge [
        (lib.mkIf config.k3s.enable {
          services.k3s = {
            enable = true;
            images = [ config.services.k3s.package.airgap-images ];
            extraFlags = [
              "--embedded-registry"
              "--disable servicelb"
              "--disable traefik"
              "--disable local-storage"
              "--disable metrics-server"
            ];
          };
        })
        (lib.mkIf (config.k3s.enable && config.secrets.enable && config.secrets.k3s.enable) {
          sops.secrets."k3s/token" = { };
          services.k3s.tokenFile = config.sops.secrets."k3s/token".path;
        })
      ];
    };
}

Extra Reading
#

NixOS Documentation
Defining k3s in Pure Nix

Kubernetes - This article is part of a series.
Part 1: This Article