2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
|
|
|
cfg = top.flannel;
|
|
|
|
|
|
|
|
# we want flannel to use kubernetes itself as configuration backend, not direct etcd
|
|
|
|
storageBackend = "kubernetes";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options.services.kubernetes.flannel = {
|
|
|
|
enable = mkEnableOption "enable flannel networking";
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.flannel = {
|
|
|
|
|
|
|
|
enable = mkDefault true;
|
|
|
|
network = mkDefault top.clusterCidr;
|
|
|
|
inherit storageBackend;
|
|
|
|
nodeName = config.services.kubernetes.kubelet.hostname;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.kubelet = {
|
|
|
|
networkPlugin = mkDefault "cni";
|
|
|
|
cni.config = mkDefault [{
|
|
|
|
name = "mynet";
|
|
|
|
type = "flannel";
|
|
|
|
cniVersion = "0.3.1";
|
|
|
|
delegate = {
|
|
|
|
isDefaultGateway = true;
|
2021-03-09 03:18:52 +00:00
|
|
|
bridge = "mynet";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
networking = {
|
|
|
|
firewall.allowedUDPPorts = [
|
|
|
|
8285 # flannel udp
|
|
|
|
8472 # flannel vxlan
|
|
|
|
];
|
2021-03-09 03:18:52 +00:00
|
|
|
dhcpcd.denyInterfaces = [ "mynet*" "flannel*" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.pki.certs = {
|
|
|
|
flannelClient = top.lib.mkCert {
|
|
|
|
name = "flannel-client";
|
|
|
|
CN = "flannel-client";
|
|
|
|
action = "systemctl restart flannel.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# give flannel som kubernetes rbac permissions if applicable
|
|
|
|
services.kubernetes.addonManager.bootstrapAddons = mkIf ((storageBackend == "kubernetes") && (elem "RBAC" top.apiserver.authorizationMode)) {
|
|
|
|
|
|
|
|
flannel-cr = {
|
2021-08-18 13:19:15 +00:00
|
|
|
apiVersion = "rbac.authorization.k8s.io/v1";
|
2020-04-24 23:36:52 +00:00
|
|
|
kind = "ClusterRole";
|
|
|
|
metadata = { name = "flannel"; };
|
|
|
|
rules = [{
|
|
|
|
apiGroups = [ "" ];
|
|
|
|
resources = [ "pods" ];
|
|
|
|
verbs = [ "get" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
apiGroups = [ "" ];
|
|
|
|
resources = [ "nodes" ];
|
|
|
|
verbs = [ "list" "watch" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
apiGroups = [ "" ];
|
|
|
|
resources = [ "nodes/status" ];
|
|
|
|
verbs = [ "patch" ];
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
flannel-crb = {
|
2021-08-18 13:19:15 +00:00
|
|
|
apiVersion = "rbac.authorization.k8s.io/v1";
|
2020-04-24 23:36:52 +00:00
|
|
|
kind = "ClusterRoleBinding";
|
|
|
|
metadata = { name = "flannel"; };
|
|
|
|
roleRef = {
|
|
|
|
apiGroup = "rbac.authorization.k8s.io";
|
|
|
|
kind = "ClusterRole";
|
|
|
|
name = "flannel";
|
|
|
|
};
|
|
|
|
subjects = [{
|
|
|
|
kind = "User";
|
|
|
|
name = "flannel-client";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
2022-01-13 20:06:32 +00:00
|
|
|
|
|
|
|
meta.buildDocsInSandbox = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|