kubernetes.nix (1779B)
1 { config, lib, pkgs, ... }: 2 3 let 4 inherit (lib) mkEnableOption mkOption mkIf mkDefault mkOverride types optionals; 5 cfg = config.profiles.kubernetes; 6 in 7 { 8 options.profiles.kubernetes = { 9 master = { 10 enable = mkEnableOption "Make this node a master node"; 11 ip = mkOption { 12 description = "master node address"; 13 type = types.str; 14 }; 15 hostname = mkOption { 16 default = "api.kube"; 17 description = "master node hostname"; 18 type = types.str; 19 }; 20 port = mkOption { 21 default = 6443; 22 description = "port the apiserver will expose"; 23 type = types.int; 24 }; 25 }; 26 }; 27 config = mkIf cfg.enable { 28 networking = { 29 firewall.allowedTCPPorts = [ 80 443 6443 ]; 30 extraHosts = "${cfg.master.ip} ${cfg.master.hostname}"; 31 }; 32 33 boot.kernelModules = [ "ceph" ]; 34 35 # packages for administration tasks 36 environment.systemPackages = with pkgs; [ 37 kubectl 38 kubernetes 39 ]; 40 41 services.kubernetes = { 42 roles = [ "node" ] ++ optionals cfg.master.enable [ "master" ]; 43 masterAddress = cfg.master.hostname; 44 apiserverAddress = "https://${cfg.master.hostname}:${toString cfg.master.port}"; 45 kubeconfig.server = "https://${cfg.master.hostname}:${toString cfg.master.port}"; 46 easyCerts = true; 47 apiserver = mkIf cfg.master.enable { 48 securePort = cfg.master.port; 49 advertiseAddress = cfg.master.ip; 50 }; 51 # TODO: Remove this when switching to 21.11 52 controllerManager.extraOpts = "--horizontal-pod-autoscaler-use-rest-clients=false"; 53 # use coredns 54 addons.dns.enable = true; 55 56 # needed if you use swap 57 kubelet.extraOpts = "--fail-swap-on=false --root-dir=/var/lib/kubelet"; 58 }; 59 }; 60 }