k8s: the controller's listener is a ClusterIP service the host dials by name
The controller's api port was a hostPort on the node, which Pod Security baseline and restricted forbid. It is a ClusterIP Service now, behind a NetworkPolicy that admits only the node. The host's resolver (the hive's dnsmasq) forwards cluster.local to CoreDNS, and the gateway dials the Service by name through nginx's resolver. tcp.hostAddress goes.
This commit is contained in:
parent
2c1dc695c5
commit
9a72d07c05
1 changed files with 355 additions and 103 deletions
|
|
@ -40,12 +40,33 @@ let
|
|||
in
|
||||
builtins.bitAnd pa.base keep == builtins.bitAnd pb.base keep;
|
||||
|
||||
# The first address of a range, and the dotted form of an integer.
|
||||
networkOf =
|
||||
cidr:
|
||||
let
|
||||
p = parseCidr cidr;
|
||||
in
|
||||
builtins.bitAnd p.base (4294967296 - pow2 (32 - p.len));
|
||||
intToIp =
|
||||
n:
|
||||
lib.concatMapStringsSep "." (d: toString (lib.mod (n / d) 256)) [
|
||||
16777216
|
||||
65536
|
||||
256
|
||||
1
|
||||
];
|
||||
|
||||
cidrType = lib.types.strMatching "([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}";
|
||||
|
||||
# k3s's own defaults, named so the flags below and the ServiceAccount
|
||||
# issuer and key paths read from one place.
|
||||
dataDir = "/var/lib/rancher/k3s";
|
||||
clusterDomain = "cluster.local";
|
||||
# k3s's default for `--cluster-dns` is the tenth address of the service
|
||||
# range (`GetIndexedIP(svcCIDR, 10)` in k3s' `pkg/cli/server/server.go`). It
|
||||
# is passed explicitly below, so the address the host's resolver forwards
|
||||
# to and the one CoreDNS gets agree by construction.
|
||||
clusterDns = intToIp (networkOf cfg.serviceCidr + 10);
|
||||
in
|
||||
{
|
||||
options.services.hyperhive.deploy.k8s = {
|
||||
|
|
@ -93,6 +114,29 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
clusterDomain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default = clusterDomain;
|
||||
description = ''
|
||||
The cluster's DNS domain (`--cluster-domain`). A Service is
|
||||
`<name>.<namespace>.svc.<this>`.
|
||||
'';
|
||||
};
|
||||
|
||||
clusterDns = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default = clusterDns;
|
||||
description = ''
|
||||
The address of the cluster's DNS service (`--cluster-dns`): the tenth
|
||||
address of {option}`services.hyperhive.deploy.k8s.serviceCidr`. The
|
||||
host's resolver forwards the cluster's domain to it.
|
||||
'';
|
||||
};
|
||||
|
||||
cniInterfaces = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [
|
||||
|
|
@ -194,6 +238,7 @@ in
|
|||
"--service-cidr=${cfg.serviceCidr}"
|
||||
"--data-dir=${dataDir}"
|
||||
"--cluster-domain=${clusterDomain}"
|
||||
"--cluster-dns=${clusterDns}"
|
||||
];
|
||||
# k3s's own images come first: with no registry the node pulls nothing,
|
||||
# not even CoreDNS.
|
||||
|
|
@ -204,5 +249,13 @@ in
|
|||
};
|
||||
|
||||
networking.firewall.trustedInterfaces = cfg.cniInterfaces;
|
||||
|
||||
# The host's resolver (the hive's dnsmasq, which the host's own
|
||||
# `/etc/resolv.conf` names) hands the cluster's domain to CoreDNS, so a
|
||||
# Service is reachable from the host by its name. The bridge's agents ask
|
||||
# the same resolver and get the same answers.
|
||||
services.dnsmasq.settings.server = lib.mkIf config.services.hyperhive.gateway.dns.enable [
|
||||
"/${clusterDomain}/${clusterDns}"
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue