2021-12-05 20:48:56 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
options,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2018-07-22 13:14:20 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
2021-12-05 20:48:56 +01:00
|
|
|
otop = options.services.kubernetes;
|
2018-07-22 13:14:20 +02:00
|
|
|
cfg = top.proxy;
|
|
|
|
in
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule
|
|
|
|
[ "services" "kubernetes" "proxy" "address" ]
|
|
|
|
[ "services" "kubernetes" "proxy" "bindAddress" ]
|
|
|
|
)
|
|
|
|
];
|
2018-07-22 13:14:20 +02:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
options.services.kubernetes.proxy = with lib.types; {
|
|
|
|
|
|
|
|
bindAddress = mkOption {
|
|
|
|
description = "Kubernetes proxy listening address.";
|
|
|
|
default = "0.0.0.0";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
2019-04-19 21:41:48 -04:00
|
|
|
enable = mkEnableOption "Kubernetes proxy";
|
2018-07-22 13:14:20 +02:00
|
|
|
|
|
|
|
extraOpts = mkOption {
|
|
|
|
description = "Kubernetes proxy extra command line options.";
|
|
|
|
default = "";
|
2021-04-13 21:54:53 +09:00
|
|
|
type = separatedString " ";
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
featureGates = mkOption {
|
2024-07-17 09:10:17 +02:00
|
|
|
description = "Attribute set of feature gates.";
|
2018-07-22 13:14:20 +02:00
|
|
|
default = top.featureGates;
|
2021-12-05 20:48:56 +01:00
|
|
|
defaultText = literalExpression "config.${otop.featureGates}";
|
2024-07-17 09:10:17 +02:00
|
|
|
type = attrsOf bool;
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
|
|
|
|
2019-11-15 05:58:35 +01:00
|
|
|
hostname = mkOption {
|
|
|
|
description = "Kubernetes proxy hostname override.";
|
|
|
|
default = config.networking.hostName;
|
|
|
|
defaultText = literalExpression "config.networking.hostName";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
2022-01-08 06:59:18 +01:00
|
|
|
kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes proxy";
|
2018-07-22 13:14:20 +02:00
|
|
|
|
|
|
|
verbosity = mkOption {
|
|
|
|
description = ''
|
|
|
|
Optional glog verbosity level for logging statements. See
|
|
|
|
<https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md>
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = nullOr int;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
2019-08-24 12:52:32 +02:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.kube-proxy = {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes Proxy Service";
|
2019-08-24 12:52:32 +02:00
|
|
|
wantedBy = [ "kubernetes.target" ];
|
|
|
|
after = [ "kube-apiserver.service" ];
|
2021-06-28 20:33:17 +01:00
|
|
|
path = with pkgs; [
|
|
|
|
iptables
|
|
|
|
conntrack-tools
|
|
|
|
];
|
2018-07-22 13:14:20 +02:00
|
|
|
serviceConfig = {
|
|
|
|
Slice = "kubernetes.slice";
|
2024-12-23 21:59:12 +01:00
|
|
|
ExecStart = ''
|
|
|
|
${top.package}/bin/kube-proxy \
|
2018-07-22 13:14:20 +02:00
|
|
|
--bind-address=${cfg.bindAddress} \
|
|
|
|
${optionalString (top.clusterCidr != null) "--cluster-cidr=${top.clusterCidr}"} \
|
2024-07-17 09:10:17 +02:00
|
|
|
${
|
|
|
|
optionalString (cfg.featureGates != { })
|
|
|
|
"--feature-gates=${
|
|
|
|
concatStringsSep "," (
|
|
|
|
builtins.attrValues (mapAttrs (n: v: "${n}=${trivial.boolToString v}") cfg.featureGates)
|
2025-04-01 20:10:43 +02:00
|
|
|
)
|
2024-07-17 09:10:17 +02:00
|
|
|
}"
|
|
|
|
} \
|
2019-11-15 05:58:35 +01:00
|
|
|
--hostname-override=${cfg.hostname} \
|
2022-01-08 06:59:18 +01:00
|
|
|
--kubeconfig=${top.lib.mkKubeConfig "kube-proxy" cfg.kubeconfig} \
|
2018-07-22 13:14:20 +02:00
|
|
|
${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
|
|
|
|
${cfg.extraOpts}
|
|
|
|
'';
|
|
|
|
WorkingDirectory = top.dataDir;
|
2019-02-21 14:34:22 +01:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 5;
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
2021-07-30 16:16:23 +01:00
|
|
|
unitConfig = {
|
|
|
|
StartLimitIntervalSec = 0;
|
|
|
|
};
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
|
|
|
|
2019-11-15 05:58:35 +01:00
|
|
|
services.kubernetes.proxy.hostname = with config.networking; mkDefault hostName;
|
|
|
|
|
2018-07-22 13:14:20 +02:00
|
|
|
services.kubernetes.pki.certs = {
|
2022-01-08 06:59:18 +01:00
|
|
|
kubeProxyClient = top.lib.mkCert {
|
2018-07-22 13:14:20 +02:00
|
|
|
name = "kube-proxy-client";
|
|
|
|
CN = "system:kube-proxy";
|
|
|
|
action = "systemctl restart kube-proxy.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.proxy.kubeconfig.server = mkDefault top.apiserverAddress;
|
|
|
|
};
|
2022-01-08 07:10:25 +01:00
|
|
|
|
|
|
|
meta.buildDocsInSandbox = false;
|
2018-07-22 13:14:20 +02:00
|
|
|
}
|