Search code examples
openshiftopenshift-client-toolsopenshift-3openshift-enterprise

How do I stop an existing open shift Port Forward


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


Solution

  • 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.