summaryrefslogtreecommitdiffstats
path: root/nix/deploy-to-kind.nix
blob: d40fd0616a513ea83d2a03887a9957daa479de9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
''