Why does our webhook fail when it runs on a host-network pod?
The Kubernetes API server reaches your nodes through a tunnel that only allows connections to specific ports on each node's IP address.
This can cause problems with webhooks that use hostNetwork: true. Unlike a webhook running in a regular pod, which listens on a pod IP address, a host-networked webhook listens directly on the node's IP address. If its port is not allowed through the tunnel, the API server cannot reach it.
When you create or update an object that triggers the webhook, the request fails with an error similar to this:
syself node tunnel refused the apiserver's dial to <node-ip>:<port> ... declare the port in the cluster variable apiserverEgressHostPorts
How to fix it
From version 1.37, you can add the webhook's port to the apiserverEgressHostPorts variable on your Cluster. This allows the API server to reach the webhook through the tunnel.
Be aware that changing this variable replaces every node in the cluster. If possible, run the webhook without hostNetwork: true instead. This needs no change to the Cluster, so no nodes are replaced.
See API server-to-webhook connectivity for instructions on configuring the allowed ports and a list of ports you cannot use.
Related questions
