1

With oc, I can portward a pod in open shift to get local access.

oc get pods
oc port-forward MY-POD-NAME  5555:5555

How do I stop it after I start it?

I've searched through

oc port-forward --help

I don't see a way to get a list of all "port-forwards" to try and get a unique name.

Error message when I try to start listening (note, my pod-name is different after redeployment)

Unable to listen on port 5555: All listeners failed to create with the following errors: Unable to create listener: Error listen tcp4 127.0.0.1:5555: bind: address already in use, Unable to create listener: Error listen tcp6: address [[::1]]:5555: missing port in address error: Unable to listen on any of the requested ports: [{5555 5555}]

URLs I have fished:

https://docs.openshift.com/enterprise/3.0/dev_guide/port_forwarding.html

https://docs.openshift.com/enterprise/3.0/cli_reference/basic_cli_operations.html

Daein Park
  • 4,393
  • 2
  • 12
  • 21
granadaCoder
  • 26,328
  • 10
  • 113
  • 146

1 Answers1

7

You should be able to stop oc port-forward by using Ctrl-C (confirmed here).

If the port is still stuck open, then you can use sudo netstat -lnp to find the PID keeping it open. For example:

$ sudo netstat -lnp | grep 5555
tcp        0      0 127.0.0.1:5555          0.0.0.0:*               LISTEN      302867/oc           
tcp6       0      0 ::1:5555                :::*                    LISTEN      302867/oc 

Once you have the PID (which is the number here : 302867/oc), you can use sudo kill -9 <PID> to end the process, and that should free up that port.

Ciaodown
  • 529
  • 5
  • 15
  • 1
    So, just to follow up. In my case CNTL-C gave me "control back" in my terminal window....AND if I tried to use the port, it failed. So in that sense, CNTL-C worked. BUT if I tried to then reissue the same "oc port-forward MY-POD-NAME 5555:5555" command....I get the exception "address already in use, Unable to create listener". (do what open-shift team??) . And that's when your netstat trick comes into play. THANKS. – granadaCoder Jan 19 '19 at 09:50