2

I'm trying to forward port 8080 for my nginx ingress controller for Kubernetes. I'm running the command:

kubectl -n nginx-ingress port-forward nginx-ingress-768dfsssd5bf-v23ja 8080:8080 --request-timeout 0
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

It just hangs on ::1 forever. Is there a log somewhere I can view to see why its hanging?

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
itinneed
  • 153
  • 2
  • 14

1 Answers1

2

Well, it's expected behaviour - kubectl port-forward is not getting daemonized by default. From the official Kubernetes documentation:

Note: kubectl port-forward does not return. To continue with the exercises, you will need to open another terminal.

The all logs will be shown in kubectl port-forward command output:

user@shell:~$ kubectl port-forward deployment/nginx-deployment 80:80
Forwarding from 127.0.0.1:80 -> 80

Including errors:

Handling connection for 88
Handling connection for 88
E1214 01:25:48.704335   51463 portforward.go:331] an error occurred forwarding 88 -> 82: error forwarding port 82 to pod a017a46573bbc065902b600f0767d3b366c5dcfe6782c3c31d2652b4c2b76941, uid : exit status 1: 2018/12/14 08:25:48 socat[19382] E connect(5, AF=2 127.0.0.1:82, 16): Connection refused

If you don't have any logs that means you didn't make an attempt to connect or you specified a wrong address / port.

As earlier mentioned, you can open a new terminal window, you can also run kubectl port-forward in the background by adding & at the end of the command:

kubectl -n nginx-ingress port-forward nginx-ingress-768dfsssd5bf-v23ja 8080:8080 --request-timeout 0 &

If you want to run kubectl port-forward in background and save all logs to the file you can use nohup command + & at the end:

nohup kubectl -n nginx-ingress port-forward nginx-ingress-768dfsssd5bf-v23ja 8080:8080 --request-timeout 0 &
Mikolaj S.
  • 2,850
  • 1
  • 5
  • 17