From d347727c4f203f4eeb1e26801cc9e73febdd3876 Mon Sep 17 00:00:00 2001 From: Jonas Juselius Date: Thu, 17 Oct 2019 20:56:32 +0200 Subject: [PATCH] Bootstrap cluster manually --- lib/k8s.nix | 70 ++++++++++++++++++++++++--------------- lib/kube-system-bootstrap | 2 +- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/lib/k8s.nix b/lib/k8s.nix index 0979539..7e26d6a 100644 --- a/lib/k8s.nix +++ b/lib/k8s.nix @@ -15,12 +15,24 @@ let kube-system-bootstrap = pkgs.stdenv.mkDerivation { name = "kube-system-bootstrap"; src = ./kube-system-bootstrap; + buildCommand = '' + mkdir -p $out + cp -r $src/* $out + ''; + }; + + bootstrap-kube-system-sh = pkgs.writeScriptBin "bootstrap-kube-system.sh" '' + #!${pkgs.bash}/bin/bash + cd ${kube-system-bootstrap} + ${pkgs.bash}/bin/bash ./kube-system-bootstrap ${cluster-ca} ${settings.clusterName} + ''; + + kube-scripts = pkgs.stdenv.mkDerivation { + name = "kube-scripts"; buildCommand = '' mkdir -p $out/bin - mkdir -p $out/share/kube-system-bootstrap - cp -r $src/* $out/share/kube-system-bootstrap/ cd $out/bin - ln -s $out/share/kube-system-bootstrap/bin/* . + ln -s ${kube-system-bootstrap}/bin/* . ''; }; @@ -84,7 +96,8 @@ rec { environment.systemPackages = [ pkgs.kubernetes-helm pkgs.kubectl - kube-system-bootstrap + kube-scripts + bootstrap-kube-system-sh ]; systemd.services.kube-certmgr-apitoken-bootstrap = { @@ -98,29 +111,29 @@ rec { }; }; - systemd.services.kube-system-bootstrap = { - description = "Kubernetes certmgr bootstrapper"; - wantedBy = [ "multi-user.target" ]; - after = [ "kubernetes.target" ]; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = false; - Environment = '' - PATH=$PATH:/run/current-system/sw/bin - ''; - ExecStart = pkgs.writeScript "kube-system-bootstrap" '' - #!${pkgs.bash}/bin/bash - set -e - if [ ! -f /var/lib/kubernetes/.kube-system-bootstrap.done ]; then - ${pkgs.bash}/bin/bash - d=${kube-system-bootstrap}/share/kube-system-bootstrap - cd $d - $d/kube-system-bootstrap ${cluster-ca} ${settings.clusterName} - touch /var/lib/kubernetes/.kube-system-bootstrap.done - fi - ''; - }; - }; +# systemd.services.kube-system-bootstrap = { +# description = "Kubernetes certmgr bootstrapper"; +# wantedBy = [ "multi-user.target" ]; +# after = [ "kubernetes.target" ]; +# serviceConfig = { +# Type = "oneshot"; +# RemainAfterExit = false; +# Environment = '' +# PATH=$PATH:/run/current-system/sw/bin +# ''; +# ExecStart = pkgs.writeScript "kube-system-bootstrap" '' +# #!${pkgs.bash}/bin/bash +# set -e +# if [ ! -f /var/lib/kubernetes/.kube-system-bootstrap.done ]; then +# sh=${pkgs.bash}/bin/bash +# d=${kube-system-bootstrap}/share/kube-system-bootstrap +# cd $d +# $sh $d/kube-system-bootstrap ${cluster-ca} ${settings.clusterName} +# touch /var/lib/kubernetes/.kube-system-bootstrap.done +# fi +# ''; +# }; +# }; }; kubeWorker = { @@ -184,6 +197,9 @@ rec { firewall.allowedTCPPorts = [ 80 443 111 ]; firewall.allowedUDPPorts = [ 111 24007 24008 ]; }; + environment.systemPackages = with pkgs; [ + nfs-utils + ]; }; apiserver = ip: name: self: diff --git a/lib/kube-system-bootstrap b/lib/kube-system-bootstrap index 0c5abbc..addf50b 160000 --- a/lib/kube-system-bootstrap +++ b/lib/kube-system-bootstrap @@ -1 +1 @@ -Subproject commit 0c5abbce4659f000340cc48efd667843657fdbc8 +Subproject commit addf50bbc0f35c7d6d4bd91754392102cc4c5cd5