1 { config, lib, pkgs, ... }:
3 top = config.services.kubernetes;
6 # we want flannel to use kubernetes itself as configuration backend, not direct etcd
7 storageBackend = "kubernetes";
11 options.services.kubernetes.flannel = {
12 enable = lib.mkEnableOption "flannel networking";
14 openFirewallPorts = lib.mkOption {
16 Whether to open the Flannel UDP ports in the firewall on all interfaces.'';
17 type = lib.types.bool;
23 config = lib.mkIf cfg.enable {
26 enable = lib.mkDefault true;
27 network = lib.mkDefault top.clusterCidr;
28 inherit storageBackend;
29 nodeName = config.services.kubernetes.kubelet.hostname;
32 services.kubernetes.kubelet = {
33 cni.config = lib.mkDefault [{
38 isDefaultGateway = true;
45 firewall.allowedUDPPorts = lib.mkIf cfg.openFirewallPorts [
49 dhcpcd.denyInterfaces = [ "mynet*" "flannel*" ];
52 services.kubernetes.pki.certs = {
53 flannelClient = top.lib.mkCert {
54 name = "flannel-client";
55 CN = "flannel-client";
56 action = "systemctl restart flannel.service";
60 # give flannel some kubernetes rbac permissions if applicable
61 services.kubernetes.addonManager.bootstrapAddons = lib.mkIf ((storageBackend == "kubernetes") && (lib.elem "RBAC" top.apiserver.authorizationMode)) {
64 apiVersion = "rbac.authorization.k8s.io/v1";
66 metadata = { name = "flannel"; };
69 resources = [ "pods" ];
74 resources = [ "nodes" ];
75 verbs = [ "list" "watch" ];
79 resources = [ "nodes/status" ];
85 apiVersion = "rbac.authorization.k8s.io/v1";
86 kind = "ClusterRoleBinding";
87 metadata = { name = "flannel"; };
89 apiGroup = "rbac.authorization.k8s.io";
95 name = "flannel-client";
102 meta.buildDocsInSandbox = false;