2021-12-19 01:06:50 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
2021-12-19 01:06:50 +00:00
|
|
|
otop = options.services.kubernetes;
|
2020-04-24 23:36:52 +00:00
|
|
|
cfg = top.proxy;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "kubernetes" "proxy" "address" ] ["services" "kubernetes" "proxy" "bindAddress"])
|
|
|
|
];
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
options.services.kubernetes.proxy = with lib.types; {
|
|
|
|
|
|
|
|
bindAddress = mkOption {
|
|
|
|
description = "Kubernetes proxy listening address.";
|
|
|
|
default = "0.0.0.0";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
|
|
|
enable = mkEnableOption "Kubernetes proxy";
|
|
|
|
|
|
|
|
extraOpts = mkOption {
|
|
|
|
description = "Kubernetes proxy extra command line options.";
|
|
|
|
default = "";
|
2021-05-03 20:48:10 +00:00
|
|
|
type = separatedString " ";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
featureGates = mkOption {
|
|
|
|
description = "List set of feature gates";
|
|
|
|
default = top.featureGates;
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalExpression "config.${otop.featureGates}";
|
2020-04-24 23:36:52 +00:00
|
|
|
type = listOf str;
|
|
|
|
};
|
|
|
|
|
|
|
|
hostname = mkOption {
|
|
|
|
description = "Kubernetes proxy hostname override.";
|
|
|
|
default = config.networking.hostName;
|
2021-12-06 16:07:01 +00:00
|
|
|
defaultText = literalExpression "config.networking.hostName";
|
2020-04-24 23:36:52 +00:00
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
|
|
|
kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes proxy";
|
|
|
|
|
|
|
|
verbosity = mkOption {
|
|
|
|
description = ''
|
|
|
|
Optional glog verbosity level for logging statements. See
|
|
|
|
<link xlink:href="https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md"/>
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = nullOr int;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.kube-proxy = {
|
|
|
|
description = "Kubernetes Proxy Service";
|
|
|
|
wantedBy = [ "kubernetes.target" ];
|
|
|
|
after = [ "kube-apiserver.service" ];
|
2021-07-03 03:11:41 +00:00
|
|
|
path = with pkgs; [ iptables conntrack-tools ];
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Slice = "kubernetes.slice";
|
|
|
|
ExecStart = ''${top.package}/bin/kube-proxy \
|
|
|
|
--bind-address=${cfg.bindAddress} \
|
|
|
|
${optionalString (top.clusterCidr!=null)
|
|
|
|
"--cluster-cidr=${top.clusterCidr}"} \
|
|
|
|
${optionalString (cfg.featureGates != [])
|
|
|
|
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
|
|
|
|
--hostname-override=${cfg.hostname} \
|
|
|
|
--kubeconfig=${top.lib.mkKubeConfig "kube-proxy" cfg.kubeconfig} \
|
|
|
|
${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
|
|
|
|
${cfg.extraOpts}
|
|
|
|
'';
|
|
|
|
WorkingDirectory = top.dataDir;
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 5;
|
|
|
|
};
|
2021-08-23 08:02:39 +00:00
|
|
|
unitConfig = {
|
|
|
|
StartLimitIntervalSec = 0;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.proxy.hostname = with config.networking; mkDefault hostName;
|
|
|
|
|
|
|
|
services.kubernetes.pki.certs = {
|
|
|
|
kubeProxyClient = top.lib.mkCert {
|
|
|
|
name = "kube-proxy-client";
|
|
|
|
CN = "system:kube-proxy";
|
|
|
|
action = "systemctl restart kube-proxy.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.proxy.kubeconfig.server = mkDefault top.apiserverAddress;
|
|
|
|
};
|
|
|
|
}
|