k8s: the queue's client port is a loadbalancer service
The queue's client port was a hostPort on 0.0.0.0, which Pod Security baseline and restricted forbid. It is a LoadBalancer Service now, which k3s's service load balancer binds on every address of the node with a hostPort of its own in kube-system, so hives on other hosts keep their URL. No node port is allocated. The stt policy allows the load balancer's pods in place of the queue's, and the prune unit waits for them to go before the host unit starts. The egress published-port rule and the raw-table rules apply to the load balancer's hostPort as to the pod's.
This commit is contained in:
parent
c2d57df7f5
commit
796fd6201f
2 changed files with 200 additions and 75 deletions
|
|
@ -370,11 +370,11 @@ let
|
|||
};
|
||||
|
||||
# What the policy of a pod that reaches `reaches` allows: the cluster's DNS,
|
||||
# those host ports, and the queue's own pod where the queue runs in the
|
||||
# cluster, because its `hostPort` is forwarded to the pod before the policy
|
||||
# sees the packet. The policy selects every pod of the service for ingress
|
||||
# too and allows none, so only the node's own traffic (the kubelet's probes,
|
||||
# which the policy engine always admits) reaches it.
|
||||
# those host ports, and the pods of the queue's load balancer where the queue
|
||||
# runs in the cluster, because the `hostPort` they bind is forwarded to them
|
||||
# before the policy sees the packet. The policy selects every pod of the
|
||||
# service for ingress too and allows none, so only the node's own traffic
|
||||
# (the kubelet's probes, which the policy engine always admits) reaches it.
|
||||
networkPolicyOf =
|
||||
name: reaches:
|
||||
let
|
||||
|
|
@ -416,7 +416,15 @@ let
|
|||
}
|
||||
]
|
||||
++ lib.optional (queueOnCluster && lib.elem "queue" reaches) {
|
||||
to = [ { podSelector.matchLabels = labelsFor "swarm-nats"; } ];
|
||||
to = [
|
||||
{
|
||||
namespaceSelector.matchLabels."kubernetes.io/metadata.name" = "kube-system";
|
||||
podSelector.matchLabels = {
|
||||
"svccontroller.k3s.cattle.io/svcname" = "swarm-nats";
|
||||
"svccontroller.k3s.cattle.io/svcnamespace" = k8sCfg.namespace;
|
||||
};
|
||||
}
|
||||
];
|
||||
ports = [ (tcp hostPorts.queue) ];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ let
|
|||
'';
|
||||
apiReady = waitFor 600 "the cluster's API" "${kubectl} get --raw /readyz >/dev/null 2>&1";
|
||||
|
||||
# The service load balancer binds a Service's port on the node with a
|
||||
# `hostPort` in a pod of `kube-system`, which its controller deletes some time
|
||||
# after the Service. The rule that forwards the port to that pod stays until
|
||||
# the pod is gone, and would swallow what the host unit then listens on.
|
||||
lbPodsGone =
|
||||
name:
|
||||
waitFor 180 "the load balancer's pods of ${name}"
|
||||
"[ -z \"\$(${kubectl} --namespace kube-system get pods --selector svccontroller.k3s.cattle.io/svcname=${name},svccontroller.k3s.cattle.io/svcnamespace=${cfg.namespace} --output name)\" ]";
|
||||
|
||||
caFiles = lib.filterAttrs (_: path: path != null) rendered.caSources;
|
||||
|
||||
# The services on the cluster whose pods run in a user namespace.
|
||||
|
|
@ -148,6 +157,7 @@ in
|
|||
${kubectl} --namespace ${cfg.namespace} delete deployment,cronjob,serviceaccount,networkpolicy,service \
|
||||
--selector=app.kubernetes.io/name=${name} \
|
||||
--cascade=foreground --wait=true --timeout=180s --ignore-not-found
|
||||
${lbPodsGone name}
|
||||
${kubectl} --namespace kube-system delete addons.k3s.cattle.io ${name} --ignore-not-found
|
||||
rm -f "$pending"
|
||||
'';
|
||||
|
|
|
|||
Loading…
Reference in a new issue