feat(kubernetes): Deploy Cyberchef using applyset
This commit is contained in:
parent
b33c3a0b82
commit
ada288674a
6 changed files with 112 additions and 39 deletions
7
flake-parts/kubenix-deploy.sh
Executable file
7
flake-parts/kubenix-deploy.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
export KUBECTL_APPLYSET=true
|
||||
vals eval -fail-on-missing-key-in-map <$MANIFEST | kubectl apply -f - --prune --applyset $APPLYSET --namespace $NAMESPACE
|
|
@ -1,4 +1,4 @@
|
|||
{ self, machines, dns, myLib, flake-utils, kubenix, nixhelm, blog-pim, ... }: flake-utils.lib.eachDefaultSystem
|
||||
{ self, pkgs, machines, dns, myLib, flake-utils, kubenix, nixhelm, blog-pim, ... }: flake-utils.lib.eachDefaultSystem
|
||||
(system:
|
||||
let
|
||||
mkKubenixPackage = module: kubenix.packages.${system}.default.override
|
||||
|
@ -6,8 +6,57 @@
|
|||
specialArgs = { inherit myLib kubenix nixhelm system dns blog-pim machines; };
|
||||
module = { imports = [ module ]; };
|
||||
};
|
||||
|
||||
deployScript = (pkgs.writeScriptBin "kubenix" (builtins.readFile ./kubenix-deploy.sh)).overrideAttrs (old: {
|
||||
buildCommand = "${old.buildCommand}\npatchShebangs $out";
|
||||
});
|
||||
|
||||
mkDeployScript = kubernetes: applyset: namespace:
|
||||
let
|
||||
kubeconfig = kubernetes.kubeconfig or "";
|
||||
result = kubernetes.result or "";
|
||||
|
||||
wrappedDeployScript = pkgs.symlinkJoin
|
||||
{
|
||||
name = "kubenix";
|
||||
paths = [ deployScript pkgs.vals pkgs.kubectl ];
|
||||
buildInputs = [ pkgs.makeWrapper ];
|
||||
passthru.manifest = result;
|
||||
|
||||
postBuild = ''
|
||||
wrapProgram $out/bin/kubenix \
|
||||
--suffix PATH : "$out/bin" \
|
||||
--run 'export KUBECONFIG=''${KUBECONFIG:-${toString kubeconfig}}' \
|
||||
--set MANIFEST '${result}' \
|
||||
--set APPLYSET '${applyset}' \
|
||||
--set NAMESPACE '${namespace}'
|
||||
'';
|
||||
};
|
||||
in
|
||||
wrappedDeployScript;
|
||||
|
||||
mkDeployScriptAndManifest = module: applyset: namespace:
|
||||
let
|
||||
kubernetes = (kubenix.evalModules.${system} {
|
||||
module = { kubenix, ... }:
|
||||
{
|
||||
imports = [
|
||||
kubenix.modules.k8s
|
||||
"${self}/kubenix-modules/custom"
|
||||
module
|
||||
];
|
||||
};
|
||||
}).config.kubernetes;
|
||||
in
|
||||
{
|
||||
kubenix = mkKubenixPackage "${self}/kubenix-modules/all.nix";
|
||||
kubenix-bootstrap = mkKubenixPackage "${self}/kubenix-modules/base.nix";
|
||||
manifest = kubernetes.result;
|
||||
deploy = mkDeployScript kubernetes applyset namespace;
|
||||
};
|
||||
in
|
||||
{
|
||||
kubenix.all.deploy = mkKubenixPackage "${self}/kubenix-modules/all.nix";
|
||||
kubenix.bootstrap.deploy = mkKubenixPackage "${self}/kubenix-modules/base.nix";
|
||||
|
||||
kubenix.cyberchef = mkDeployScriptAndManifest
|
||||
"${self}/kubenix-modules/cyberchef.nix" "cyberchef" "cyberchef";
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
let
|
||||
applications = [
|
||||
./freshrss.nix
|
||||
./cyberchef.nix
|
||||
# ./cyberchef.nix
|
||||
./kms.nix
|
||||
./inbucket.nix
|
||||
./radicale.nix
|
||||
|
@ -31,9 +31,7 @@ in
|
|||
./ek2024.nix
|
||||
./metallb.nix
|
||||
./cert-manager.nix
|
||||
./custom/ingress.nix
|
||||
./custom/nfs-volume.nix
|
||||
./custom/longhorn-volume.nix
|
||||
./custom
|
||||
./traefik.nix
|
||||
./volumes.nix
|
||||
./custom-types.nix
|
||||
|
|
|
@ -59,7 +59,8 @@
|
|||
};
|
||||
};
|
||||
|
||||
resources.nodes =
|
||||
resources = {
|
||||
nodes =
|
||||
let
|
||||
machinesWithKubernetesLabels = lib.filterAttrs (name: machine: machine.kubernetesNodeLabels != null) machines;
|
||||
in
|
||||
|
@ -70,4 +71,5 @@
|
|||
machinesWithKubernetesLabels;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
7
kubenix-modules/custom/default.nix
Normal file
7
kubenix-modules/custom/default.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
imports = [
|
||||
./ingress.nix
|
||||
./longhorn-volume.nix
|
||||
./nfs-volume.nix
|
||||
];
|
||||
}
|
|
@ -1,5 +1,13 @@
|
|||
{
|
||||
kubernetes.resources = {
|
||||
config = {
|
||||
kubenix.project = "cyberchef";
|
||||
|
||||
kubernetes = {
|
||||
namespace = "cyberchef";
|
||||
|
||||
resources = {
|
||||
namespaces.cyberchef = { };
|
||||
|
||||
deployments.cyberchef.spec = {
|
||||
replicas = 3;
|
||||
selector.matchLabels.app = "cyberchef";
|
||||
|
@ -23,6 +31,7 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
lab.ingresses.cyberchef = {
|
||||
host = "cyberchef.kun.is";
|
||||
|
@ -32,4 +41,5 @@
|
|||
portName = "web";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue