diff options
Diffstat (limited to 'nix/deploy-to-kind.nix')
-rw-r--r-- | nix/deploy-to-kind.nix | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nix/deploy-to-kind.nix b/nix/deploy-to-kind.nix new file mode 100644 index 0000000..d40fd06 --- /dev/null +++ b/nix/deploy-to-kind.nix @@ -0,0 +1,51 @@ +{ kind +, helloImage +, worldImage +, joinerImage +, clusterName ? "cluster" +, config +, pkgs }: + +let + kindConfig = pkgs.writeText "kind-config" '' + kind: Cluster + apiVersion: kind.x-k8s.io/v1alpha4 + nodes: + - role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + extraPortMappings: + - containerPort: 80 + hostPort: 8080 + protocol: TCP + - containerPort: 443 + hostPort: 8443 + protocol: TCP + ''; +in + +pkgs.writeScriptBin "deploy-to-kind" '' + #! ${pkgs.runtimeShell} + set -euo pipefail + + ${kind}/bin/kind delete ${clusterName} || true + ${kind}/bin/kind create ${clusterName} --config ${kindConfig} + + echo "Loading the ${pkgs.docker}/bin/docker image inside the kind docker container ..." + + kind load image-archive <(gzip --decompress --stdout ${helloImage}) + kind load image-archive <(gzip --decompress --stdout ${worldImage}) + kind load image-archive <(gzip --decompress --stdout ${joinerImage}) + + echo "Applying the configuration ..." + cat ${config} | ${pkgs.jq}/bin/jq "." + cat ${config} | ${pkgs.kubectl}/bin/kubectl apply -f - + + echo "Applying nginx ingress ..." + kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml +'' + |