i have WSL2 with Ubuntu 22.04.3 LTS on Windows 10, all the latest updates. "kubectl port-forward" command in wsl used to work just fine, exactly like it does on the windows host machine. until today i suddenly discovered that it does not any more (but from windows everything still works). on wsl i am now getting this:
kubectl port-forward --kubeconfig=/home/my_config.yaml --namespace=my_namespace service/my_service 9092:9092
error: error upgrading connection: error sending request: Post "https://remote_ip:port/k8s/clusters/abc/api/v1/namespaces/my_namespace/pods/my_pod/portforward": read tcp local_ip:port->remote_ip:port: read: connection reset by peer
what happenned? i have like three programs installed in wsl, IDE and kubectl, all with default settings, port-forwarding worked in wsl out-of-the box, and now it doesn't..
this command requires kubectl to be able to open a port in wsl? how come it worked and now doesn't?
PS: cluster is perfectly accessible, any of these work:
kubectl get pod
kubectl cluster-info
kubectl config view
kubectl get all --all-namespaces
EDIT: just installed Lens desktop in wsl, it has no problem doing this exact port-forward. so its only this command line use of kubectl, as quoted above, stopped working.
The error "
read:connection reset by peer" indicates an issue during the port forwarding establishment, often due to an inability to connect to the kubernetes API server's port of limitations in WSL2 or related applications.You can try these steps as troubleshooting to fix the concern:
Restart services: you can restart WSL2 by using this command "
wsl --shutdown" then followed by "wsl --unregister <distro\_name\>" and then "wsl --register <distro\_name\>". If using Docker within WSL2, restart it: "sudo systemctl restart docker"Clean Kubernetes Configuration: Delete and re-create your
kubeconfig.yamlfile using the appropriate method or create a new configuration withkubectl config cluster(...).Test with
nestat: On the WSL2 side, use nestat -lptn before and after runningkubectl port-forwardto check for opened ports.Use a different port: Trying a different port number for the forwarded port to rule-out port-specific conflicts.
Verify
kubectlinstallation: Reinstallkubectlif necessary or use a different version that may work.Check Permissions: Ensure that
kubectlhas the necessary permissions to access the pod:kubectl auth can-i create podbindings -n my\_namespaceWSL2 Integration Check: If the issue started after the new software or WSL2 updates, temporarily remove or rollback to isolate the cause