6

I am running a k8s cluster on bare-metal RHEL7. I am trying to run the kubectl port-forward command and am getting a error.

kubectl port-forward -p somepod 10000:8080
I0128 15:33:33.802226   70558 portforward.go:225] Forwarding from 127.0.0.1:10000 -> 8080                                                        
E0128 15:33:33.802334   70558 portforward.go:214] Unable to create listener: Error listen tcp6 [::1]:10000: bind: cannot assign requested address

Any ideas why this could be happening?

dmm
  • 61
  • 1
  • 1
  • 4
  • Probably is port 10000 on IPv6 address already allocated or it was used by OS recently. Is IPv6 enabled? Did check port 10000 with netstat/ss command? – Jan Garaj Jan 29 '16 at 00:19
  • The port had not been used up and IPv6 is enabled. I verified that it wasn't being used and also played around with the port number just in case. – dmm Jan 30 '16 at 00:43
  • 2
    Have you tried `sudo`? – kichik May 12 '16 at 18:26
  • This is what fixed it for me: https://stackoverflow.com/a/62359555/2441655 – Venryx Aug 27 '21 at 01:34

1 Answers1

1

If you run kubectl port-forward multiple times, and you have ipv6 enabled on your machine you will run on this quite often.

There are two solutions:

  1. Run netstat -nlp | grep 10000 in order to know the PID of the process using that port. Then you can kill it with kill -9 PID_OF_PROCESS
  2. Permanent solution: disable ipv6

    echo "
    net.ipv6.conf.all.disable_ipv6=1
    net.ipv6.conf.default.disable_ipv6=1
    net.ipv6.conf.lo.disable_ipv6=1
    " | sudo tee -a /etc/sysctl.conf reboot"

GNUton
  • 1,129
  • 8
  • 7