Skip to content

Port Forward deleted without UI notification when forwarding to wrong port #3301

@igorakkerman

Description

@igorakkerman




Describe the bug
When I create a port forward to the wrong port, the port forward gets deleted without a UI notification. The error message in the log is not expressive.

When creating the port forward on a service, rather than on a pod, and the service exposes a different port than the pod does, it's easy to run into that issue, see below.

To Reproduce

  1. kubectl run nginx --image nginx
  2. In k9s, use Shift+F to create a port forward
  3. Enter 81 as container and local ports
  4. curl --verbose 'http://127.0.0.1:81/'
*   Trying 127.0.0.1:81...
* Connected to 127.0.0.1 (127.0.0.1) port 81
* using HTTP/1.x
> GET / HTTP/1.1
> Host: 127.0.0.1:81
> User-Agent: curl/8.11.1
> Accept: */*
>
* Recv failure: Connection was aborted
* closing connection #0
curl: (56) Recv failure: Connection was aborted
  1. See the port forward getting deleted without notification.
  2. Find error message in k9s.log:
Flash failed error="lost connection to pod"
Deleted portforward count=1 gvr=nginx||81:81

Expected behavior

  • UI message stating that the port forward was deleted, potentially giving a possible reason.
  • Expressive message in the log.

Versions:

  • OS: Windows 11
  • K9s: 0.50.4
  • K8s: 1.32.2

Additional context
I ran into this issue trying to connect to a service, which exposes port 80 and has targetPort 8080. I used port 80 in k9s as I did with kubectl:

kubectl port-forward svc/myservice 80:80

While kubectl forwards to 8080, k9s suggests 8080 but lets you enter any port, 80 in my case.
I didn't notice the pod's port in the kubectl output:

Forwarding from 127.0.0.1:80 -> 8080
Forwarding from [::1]:80 -> 8080

That's how I got stuck with the connection failing with k9s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-progressMark issue as being worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions