Skip to content

Commit 0f545d0

Browse files
kill-host-pods.py: filter pods by node
Starting with k8s 1.32, AuthorizeNodeWithSelectors is enabled by default: https://kubernetes.io/docs/reference/access-authn-authz/node/ If the rbac microk8s addon is enabled, the kube-apiserver will run with "--authorization-mode=RBAC,Node". This means that kublets (system:node:$node) will no longer be allowed to access pods that reside on other nodes. For this reason, the "kill-host-pods.py" script is now getting access denied errors: Error from server (Forbidden): pods is forbidden: User "system:node:myhostname" cannot list resource "pods" in API group "" at the cluster scope: can only list/watch pods with spec.nodeName field selector As suggested by the error message, we'll solve it by filtering pods by the node name. Fixes: #4802
1 parent 47ade06 commit 0f545d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

microk8s-resources/default-hooks/reconcile.d/10-pods-restart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
if ! [ -e "${SNAP_DATA}/var/lock/no-cni-reload" ] &&
66
[ -e "${SNAP_DATA}/var/lock/snapdata-mounts-need-reload" ]; then
7-
if (is_apiserver_ready) && "${SNAP}/scripts/kill-host-pods.py" --with-snap-data-mounts --with-owner -- -A; then
7+
if (is_apiserver_ready) && "${SNAP}/scripts/kill-host-pods.py" \
8+
--with-snap-data-mounts --with-owner \
9+
-- -A --field-selector spec.nodeName=$(hostname) ; then
810
rm "${SNAP_DATA}/var/lock/snapdata-mounts-need-reload"
911
fi
1012
fi

0 commit comments

Comments
 (0)