From 35bcff9d6f0b8744e285321aa115227139a07596 Mon Sep 17 00:00:00 2001 From: Jonas Juselius Date: Wed, 22 Sep 2021 21:05:44 +0200 Subject: [PATCH] Update k0 to multi etcd --- clusters/k0/cluster.nix | 33 +++++++++++++++++++------------ clusters/k0/default.nix | 43 +++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/clusters/k0/cluster.nix b/clusters/k0/cluster.nix index ed4bd80..c3a500e 100644 --- a/clusters/k0/cluster.nix +++ b/clusters/k0/cluster.nix @@ -1,7 +1,7 @@ { pkgs, lib, config, ... }: with lib; let - cfg = config.node; + cfg = config.features.k8s.host; mkSANs = host: [ host.name @@ -91,20 +91,29 @@ let address = cfg.address; }; + fileSystems = { + "/vol/local-storage/vol1" = { + device = "/vol/vol1"; + options = [ "bind" ]; + }; + "/vol/local-storage/vol2" = { + device = "/vol/vol2"; + options = [ "bind" ]; + }; + }; }; in { - options.node = { - address = mkOption { - type = types.str; - default = null; - }; + # options.node = { + # address = mkOption { + # type = types.str; + # default = null; + # }; - name = mkOption { - type = types.str; - default = null; - }; - - }; + # name = mkOption { + # type = types.str; + # default = null; + # }; + # }; config = configuration; diff --git a/clusters/k0/default.nix b/clusters/k0/default.nix index f973cd6..2f13461 100644 --- a/clusters/k0/default.nix +++ b/clusters/k0/default.nix @@ -1,13 +1,25 @@ # Pin the deployment package-set to a specific version of nixpkgs -# with import {}; -with import ../nixos-21.05.nix {}; +# with import ../nixos-21.05.nix {}; +with import {}; let + etcdNodes = { + k0-0 = "10.1.8.50"; + k0-1 = "10.1.8.51"; + k0-2 = "10.1.8.52"; + }; master = { - node.name = "k0-0"; - node.address = "10.1.8.50"; - features.k8s.master.enable = true; - features.k8s.nodes = nodes; + features.k8s = { + host.name = "k0-0"; + host.address = "10.1.8.50"; + master.enable = true; + nodes = nodes; + etcdCluster = { + enable = true; + existing = true; + nodes = etcdNodes; + }; + }; services.kubernetes.kubelet.unschedulable = true; imports = [ ./cluster.nix ./hw/k0-0.nix ]; }; @@ -19,13 +31,24 @@ let mkNode = x: { "${x.name}" = + lib.mkMerge [ { - node = x; - imports = [ ./cluster.nix (./hw + "/${x.name}.nix") ]; - }; + features.k8s.host = x; + } + (if builtins.hasAttr x.name etcdNodes then + { + features.k8s.etcdCluster = { + enable = true; + existing = true; + nodes = etcdNodes; + }; + } + else {}) + ] + // { imports = [ ./cluster.nix (./hw + "/${x.name}.nix") ]; }; }; in builtins.foldl' (a: x: a // mkNode x) { - "${master.node.name}" = master; + "${master.features.k8s.host.name}" = master; } nodes