Add option to add labels to Kubernetes nodes

Make nextcloud always go to nodes with fast storage
Don't mount nextcloud on syncthing pod
This commit is contained in:
Pim Kunis 2024-05-24 23:40:19 +02:00
parent 11200c0ff7
commit afa0bd023e
8 changed files with 41 additions and 9 deletions

View file

@ -1,9 +1,9 @@
{ dns, myLib, flake-utils, kubenix, nixhelm, blog-pim, ... }: flake-utils.lib.eachDefaultSystem { machines, dns, myLib, flake-utils, kubenix, nixhelm, blog-pim, ... }: flake-utils.lib.eachDefaultSystem
(system: (system:
let let
mkKubenixPackage = module: kubenix.packages.${system}.default.override mkKubenixPackage = module: kubenix.packages.${system}.default.override
{ {
specialArgs = { inherit myLib kubenix nixhelm system dns blog-pim; }; specialArgs = { inherit myLib kubenix nixhelm system dns blog-pim machines; };
module = { imports = [ module ]; }; module = { imports = [ module ]; };
}; };
in in

View file

@ -15,10 +15,10 @@ let
./media.nix ./media.nix
./bind9 ./bind9
./dnsmasq.nix ./dnsmasq.nix
# ./minecraft.nix
./blog.nix ./blog.nix
./atticd.nix ./atticd.nix
# ./argo.nix # ./argo.nix
# ./minecraft.nix
]; ];
in in
{ {

View file

@ -1,6 +1,6 @@
# We deploy several resources that rely on "custom resource definitions". # We deploy several resources that rely on "custom resource definitions".
# We must first import these resources definitions, before deploying resources that depend on them. # We must first import these resources definitions, before deploying resources that depend on them.
{ kubenix, nixhelm, system, ... }: { { lib, kubenix, nixhelm, system, machines, ... }: {
imports = [ imports = [
kubenix.modules.k8s kubenix.modules.k8s
kubenix.modules.helm kubenix.modules.helm
@ -58,6 +58,16 @@
}; };
}; };
}; };
resources.nodes =
let
machinesWithKubernetesLabels = lib.filterAttrs (name: machine: machine.kubernetesNodeLabels != null) machines;
in
builtins.mapAttrs
(name: machine: {
metadata.labels = machine.kubernetesNodeLabels;
})
machinesWithKubernetesLabels;
}; };
}; };
} }

View file

@ -13,6 +13,14 @@
spec = { spec = {
selector.matchLabels.app = "nextcloud"; selector.matchLabels.app = "nextcloud";
strategy = {
type = "RollingUpdate";
rollingUpdate = {
maxSurge = 0;
maxUnavailable = 1;
};
};
template = { template = {
metadata.labels.app = "nextcloud"; metadata.labels.app = "nextcloud";
@ -40,6 +48,15 @@
fsGroup = 33; fsGroup = 33;
fsGroupChangePolicy = "OnRootMismatch"; fsGroupChangePolicy = "OnRootMismatch";
}; };
affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution = [{
weight = 1;
preference.matchExpressions = [{
key = "storageType";
operator = "In";
values = [ "fast" ];
}];
}];
}; };
}; };
}; };

View file

@ -26,10 +26,6 @@
name = "config"; name = "config";
mountPath = "/config"; mountPath = "/config";
} }
{
name = "nextcloud-data";
mountPath = "/data";
}
{ {
name = "music"; name = "music";
mountPath = "/music"; mountPath = "/music";
@ -39,7 +35,6 @@
volumes = { volumes = {
config.persistentVolumeClaim.claimName = "syncthing"; config.persistentVolumeClaim.claimName = "syncthing";
nextcloud-data.persistentVolumeClaim.claimName = "nextcloud";
music.persistentVolumeClaim.claimName = "music"; music.persistentVolumeClaim.claimName = "music";
}; };

View file

@ -1,6 +1,7 @@
{ {
machines.atlas = { machines.atlas = {
arch = "x86_64-linux"; arch = "x86_64-linux";
kubernetesNodeLabels.storageType = "slow";
nixosModule.lab = { nixosModule.lab = {
storage = { storage = {

View file

@ -22,6 +22,14 @@ let
Customized configuration for this machine in the form of a NixOS module. Customized configuration for this machine in the form of a NixOS module.
''; '';
}; };
kubernetesNodeLabels = lib.mkOption {
default = null;
type = with lib.types; nullOr attrs;
description = ''
Any labels to add to the Kubernetes node.
'';
};
}; };
}; };
in in

View file

@ -1,6 +1,7 @@
{ {
machines.jefke = { machines.jefke = {
arch = "x86_64-linux"; arch = "x86_64-linux";
kubernetesNodeLabels.storageType = "fast";
nixosModule.lab = { nixosModule.lab = {
storage = { storage = {