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:
let
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 ]; };
};
in

View file

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

View file

@ -1,6 +1,6 @@
# We deploy several resources that rely on "custom resource definitions".
# We must first import these resources definitions, before deploying resources that depend on them.
{ kubenix, nixhelm, system, ... }: {
{ lib, kubenix, nixhelm, system, machines, ... }: {
imports = [
kubenix.modules.k8s
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 = {
selector.matchLabels.app = "nextcloud";
strategy = {
type = "RollingUpdate";
rollingUpdate = {
maxSurge = 0;
maxUnavailable = 1;
};
};
template = {
metadata.labels.app = "nextcloud";
@ -40,6 +48,15 @@
fsGroup = 33;
fsGroupChangePolicy = "OnRootMismatch";
};
affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution = [{
weight = 1;
preference.matchExpressions = [{
key = "storageType";
operator = "In";
values = [ "fast" ];
}];
}];
};
};
};

View file

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

View file

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

View file

@ -22,6 +22,14 @@ let
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

View file

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