blob: 20b766f4020e9ddf379d3912a99e851a00179d55 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
{ config, lib, pkgs, nixpkgs, ... }:
with lib;
let
cfg = config.kubernetes;
clusterDomain = "kube.vapor.systems";
externalIP = {
v4 = if cfg.externalIP.v4 != "" then
cfg.externalIP.v4
else
(lib.elemAt config.networking.interfaces.eth0.ipv4.addresses 0).address;
v6 = if cfg.externalIP.v6 != "" then
cfg.externalIP.v6
else
(lib.elemAt config.networking.interfaces.eth0.ipv6.addresses 0).address;
};
internalIP = {
v4 = config.wireguard.v4.address;
v6 = "${config.wireguard.v6.ula}::${config.wireguard.v6.address}";
};
in {
imports = [
./cri-o.nix
];
options = {
kubernetes = {
role = mkOption {
type = types.enum [ "server" "agent" ];
description = "Act as control plane or worker node";
};
labels = mkOption {
type = types.attrs;
description = "Address the k8s api is advertised on";
default = { };
};
taints = mkOption {
type = types.attrs;
description = "Address the k8s api is advertised on";
default = { };
};
advertiseAddress = mkOption {
type = types.str;
description = "Address the k8s api is advertised on";
};
externalIP = {
v4 = mkOption {
type = types.str;
description = "External Node IP Address";
default = "";
};
v6 = mkOption {
type = types.str;
description = "External Node IP Address";
default = "";
};
};
};
};
config = {
networking.extraHosts = ''
10.10.0.1 ${clusterDomain}
fd15:3d8c:d429:beef::1 ${clusterDomain}
'';
environment.etc = {
"k3s/config.yaml" = {
text = generators.toJSON { } ({
container-runtime-endpoint = "/run/crio/crio.sock";
node-ip = "${internalIP.v4},${internalIP.v6}";
node-external-ip = "${internalIP.v4},${internalIP.v6}";
node-label =
attrValues (mapAttrs (n: v: "${n}=${toString v}") cfg.labels);
node-taint =
attrValues (mapAttrs (n: v: "${n}=${toString v}") cfg.taints);
kubelet-arg = "cgroup-driver=systemd";
no-flannel = true;
} // (if cfg.role == "server" then {
advertise-address = "${internalIP.v4}";
kube-controller-manager-arg = "node-cidr-mask-size-ipv6=72";
cluster-cidr = "10.102.0.0/16,fd15:3d8c:d429:0102::/64";
service-cidr = "10.101.0.0/16,fd15:3d8c:d429:0101::/108";
cluster-dns = "10.101.0.10";
cluster-domain = clusterDomain;
disable = [ "servicelb" "traefik" "local-storage" ];
disable-kube-proxy = true;
disable-network-policy = true;
flannel-backend = "none";
} else
{ }));
};
};
services.k3s = {
enable = true;
role = cfg.role;
token = "YPoyiPeBpQpB7oK8";
serverAddr = "https://10.10.0.1:6443";
configPath = "/etc/k3s/config.yaml";
disableAgent = cfg.role == "agent";
};
};
}
|