2018-07-22 12:14:20 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
|
|
|
cfg = top.proxy;
|
|
|
|
in
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "kubernetes" "proxy" "address" ] ["services" "kubernetes" "proxy" "bindAddress"])
|
|
|
|
];
|
2018-07-22 12:14:20 +01: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-20 02:41:48 +01:00
|
|
|
enable = mkEnableOption "Kubernetes proxy";
|
2018-07-22 12:14:20 +01:00
|
|
|
|
|
|
|
extraOpts = mkOption {
|
|
|
|
description = "Kubernetes proxy extra command line options.";
|
|
|
|
default = "";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
|
|
|
featureGates = mkOption {
|
|
|
|
description = "List set of feature gates";
|
|
|
|
default = top.featureGates;
|
|
|
|
type = listOf str;
|
|
|
|
};
|
|
|
|
|
2019-11-15 04:58:35 +00:00
|
|
|
hostname = mkOption {
|
|
|
|
description = "Kubernetes proxy hostname override.";
|
|
|
|
default = config.networking.hostName;
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
2018-07-22 12:14:20 +01:00
|
|
|
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
|
2019-08-24 11:52:32 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.kube-proxy = {
|
2018-07-22 12:14:20 +01:00
|
|
|
description = "Kubernetes Proxy Service";
|
2019-08-24 11:52:32 +01:00
|
|
|
wantedBy = [ "kubernetes.target" ];
|
|
|
|
after = [ "kube-apiserver.service" ];
|
|
|
|
path = with pkgs; [ iptables conntrack_tools ];
|
2018-07-22 12:14:20 +01: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}"} \
|
2019-11-15 04:58:35 +00:00
|
|
|
--hostname-override=${cfg.hostname} \
|
2019-08-24 11:52:32 +01:00
|
|
|
--kubeconfig=${top.lib.mkKubeConfig "kube-proxy" cfg.kubeconfig} \
|
2018-07-22 12:14:20 +01:00
|
|
|
${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
|
|
|
|
${cfg.extraOpts}
|
|
|
|
'';
|
|
|
|
WorkingDirectory = top.dataDir;
|
2019-02-21 13:34:22 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 5;
|
2018-07-22 12:14:20 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-11-15 04:58:35 +00:00
|
|
|
services.kubernetes.proxy.hostname = with config.networking; mkDefault hostName;
|
|
|
|
|
2018-07-22 12:14:20 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|