'How to connect VScode "Remote-SSH" using kubectl?

Trying to develop in VSCode with Remote Connection and run/debug/... in a pod on kubernetes cluster.

How to connect VScode using kubectl?

Trying port forwarding

kubectl -n dev port-forward my-pod-name 22:22

It connects, works but getting errors:

E0604 10:58:15.025638   11216 portforward.go:385] error copying from local connection 
to remote stream: read tcp4 127.0.0.1:22->127.0.0.1:54495: wsarecv: An existing 
connection was forcibly closed by the remote host.


Solution 1:[1]

Port 22 is a dedicated port which is reserved in your system that is why the connection cannot be established. Use the following snippet:

kubectl -n dev port-forward my-pod-name 8022:22

Solution 2:[2]

Maybe in the pod there is no running ssh-server?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erik Jagyugya
Solution 2 Brice187