2018-07-22 13:14:20 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
|
|
|
cfg = top.proxy;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
###### 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 03:41:48 +02:00
|
|
|
enable = mkEnableOption "Kubernetes proxy";
|
2018-07-22 13:14:20 +02: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03-11 11:01:54 +01:00
|
|
|
config = let
|
|
|
|
|
|
|
|
proxyPaths = filter (a: a != null) [
|
|
|
|
cfg.kubeconfig.caFile
|
|
|
|
cfg.kubeconfig.certFile
|
|
|
|
cfg.kubeconfig.keyFile
|
|
|
|
];
|
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
|
|
|
systemd.services.kube-proxy = rec {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes Proxy Service";
|
2019-03-06 17:17:20 +01:00
|
|
|
wantedBy = [ "kube-node-online.target" ];
|
2019-03-06 16:40:27 +01:00
|
|
|
after = [ "kubelet-online.service" ];
|
2019-03-06 17:17:20 +01:00
|
|
|
before = [ "kube-node-online.target" ];
|
2019-03-11 11:01:54 +01:00
|
|
|
environment.KUBECONFIG = top.lib.mkKubeConfig "kube-proxy" cfg.kubeconfig;
|
|
|
|
path = with pkgs; [ iptables conntrack_tools kubectl ];
|
2019-03-01 08:44:45 +01:00
|
|
|
preStart = ''
|
2019-03-11 11:01:54 +01:00
|
|
|
until kubectl auth can-i get nodes/${top.kubelet.hostname} -q 2>/dev/null; do
|
|
|
|
echo kubectl auth can-i get nodes/${top.kubelet.hostname}: exit status $?
|
|
|
|
sleep 2
|
|
|
|
done
|
2019-03-01 08:44:45 +01:00
|
|
|
'';
|
2018-07-22 13:14:20 +02: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-03-11 11:01:54 +01:00
|
|
|
--kubeconfig=${environment.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
|
|
|
};
|
2019-03-11 11:01:54 +01:00
|
|
|
unitConfig.ConditionPathExists = proxyPaths;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.paths.kube-proxy = {
|
|
|
|
wantedBy = [ "kube-proxy.service" ];
|
|
|
|
pathConfig = {
|
|
|
|
PathExists = proxyPaths;
|
|
|
|
PathChanged = proxyPaths;
|
|
|
|
};
|
2018-07-22 13:14:20 +02: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;
|
|
|
|
};
|
|
|
|
}
|