🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Fixes
Today I Fixed

kubectl port-forward keeps disconnecting after 60 seconds

kubectlMay 26, 202625 minutes to fixkubernetes

The problem: kubectl port-forward was silently dropping the connection every ~60 seconds. No error message — just stops working.

The fix:

bash
# Add keepalive flag
kubectl port-forward pod/mypod 8080:8080 --keepalive=60s
 
# Or just loop it
while true; do kubectl port-forward pod/mypod 8080:8080; done

Why it happens: Load balancer in front of the Kubernetes API server has a 60s idle timeout. The connection looks idle (no traffic) and gets dropped.

The --keepalive flag sends periodic TCP keepalive packets to prevent the LB from killing the connection.