Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl port-forward failing

Tags:

kubernetes

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?

like image 534
dmm Avatar asked Jan 28 '16 23:01

dmm


1 Answers

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"

like image 89
GNUton Avatar answered Sep 30 '22 20:09

GNUton