Skip to content

Commit

Permalink
kill-host-pods.py: filter pods by node
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petrutlucian94 committed Jan 10, 2025
1 parent 47ade06 commit 0f545d0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion microk8s-resources/default-hooks/reconcile.d/10-pods-restart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

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

0 comments on commit 0f545d0

Please sign in to comment.