Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster-init Flag Applied to All k3s Nodes Instead of Only the Initial Node in Configuration #5

Open
h3nryc0ding opened this issue Oct 31, 2024 · 0 comments

Comments

@h3nryc0ding
Copy link

Describe the Issue
In the current configuration, all k3s nodes appear to be initialized with the --cluster-init flag, despite clusterInit being explicitly set to true only for the primary node (homelab-0). This results in unintended behavior where each server in the cluster runs as an initial server node.

services.k3s = {
enable = true;
role = "server";
tokenFile = /var/lib/rancher/k3s/server/token;
extraFlags = toString ([
"--write-kubeconfig-mode \"0644\""
"--cluster-init"
"--disable servicelb"
"--disable traefik"
"--disable local-storage"
] ++ (if meta.hostname == "homelab-0" then [] else [
"--server https://homelab-0:6443"
]));
clusterInit = (meta.hostname == "homelab-0");
};

services.k3s = { 
   enable = true; 
   role = "server"; 
   tokenFile = /var/lib/rancher/k3s/server/token; 
   extraFlags = toString ([ 
      "--write-kubeconfig-mode \"0644\"" 
      "--cluster-init" 
      "--disable servicelb" 
      "--disable traefik" 
      "--disable local-storage" 
   ] ++ (if meta.hostname == "homelab-0" then [] else [ 
      "--server https://homelab-0:6443" 
   ])); 
   clusterInit = (meta.hostname == "homelab-0"); 
}; 

The expectation is that clusterInit would apply only to homelab-0. However, setting --cluster-init in extraFlags causes all nodes to receive this flag, effectively overriding the clusterInit condition.

Relevant Code in nixpkgs
The NixOS k3s service configuration processes clusterInit separately from extraFlags, meaning additional flags in extraFlags are simply appended rather than overriding the conditions set by clusterInit:

https://github.com/NixOS/nixpkgs/blob/44cb05c5e6f21e8f80333d7c9eebae456d595f57/nixos/modules/services/cluster/k3s/default.nix#L515-L517

Expected Behavior
Only the primary node, homelab-0, should initialize the cluster with --cluster-init, while all other nodes should connect to it using --server https://homelab-0:6443.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant