1 { config, lib, pkgs, ... }:
6 top = config.services.kubernetes;
7 cfg = top.addonManager;
9 isRBACEnabled = elem "RBAC" top.apiserver.authorizationMode;
11 addons = pkgs.runCommand "kubernetes-addons" { } ''
13 # since we are mounting the addons to the addon manager, they need to be copied
14 ${concatMapStringsSep ";" (a: "cp -v ${a}/* $out/") (mapAttrsToList (name: addon:
15 pkgs.writeTextDir "${name}.json" (builtins.toJSON addon)
21 options.services.kubernetes.addonManager = with lib.types; {
23 bootstrapAddons = mkOption {
25 Bootstrap addons are like regular addons, but they are applied with cluster-admin rights.
26 They are applied at addon-manager startup only.
30 example = literalExpression ''
36 "name" = "my-service";
37 "namespace" = "default";
46 description = "Kubernetes addons (any kind of Kubernetes resource can be an addon).";
48 type = attrsOf (either attrs (listOf attrs));
49 example = literalExpression ''
55 "name" = "my-service";
56 "namespace" = "default";
61 // import <nixpkgs/nixos/modules/services/cluster/kubernetes/dns.nix> { cfg = config.services.kubernetes; };
65 enable = mkEnableOption "Kubernetes addon manager";
69 config = mkIf cfg.enable {
70 environment.etc."kubernetes/addons".source = "${addons}/";
72 systemd.services.kube-addon-manager = {
73 description = "Kubernetes addon manager";
74 wantedBy = [ "kubernetes.target" ];
75 after = [ "kube-apiserver.service" ];
76 environment.ADDON_PATH = "/etc/kubernetes/addons/";
79 Slice = "kubernetes.slice";
80 ExecStart = "${top.package}/bin/kube-addons";
81 WorkingDirectory = top.dataDir;
84 Restart = "on-failure";
88 StartLimitIntervalSec = 0;
92 services.kubernetes.addonManager.bootstrapAddons = mkIf isRBACEnabled
94 name = "system:kube-addon-manager";
95 namespace = "kube-system";
99 kube-addon-manager-r = {
100 apiVersion = "rbac.authorization.k8s.io/v1";
103 inherit name namespace;
112 kube-addon-manager-rb = {
113 apiVersion = "rbac.authorization.k8s.io/v1";
114 kind = "RoleBinding";
116 inherit name namespace;
119 apiGroup = "rbac.authorization.k8s.io";
124 apiGroup = "rbac.authorization.k8s.io";
130 kube-addon-manager-cluster-lister-cr = {
131 apiVersion = "rbac.authorization.k8s.io/v1";
132 kind = "ClusterRole";
134 name = "${name}:cluster-lister";
143 kube-addon-manager-cluster-lister-crb = {
144 apiVersion = "rbac.authorization.k8s.io/v1";
145 kind = "ClusterRoleBinding";
147 name = "${name}:cluster-lister";
150 apiGroup = "rbac.authorization.k8s.io";
151 kind = "ClusterRole";
152 name = "${name}:cluster-lister";
161 services.kubernetes.pki.certs = {
162 addonManager = top.lib.mkCert {
163 name = "kube-addon-manager";
164 CN = "system:kube-addon-manager";
165 action = "systemctl restart kube-addon-manager.service";
170 meta.buildDocsInSandbox = false;