I am trying to follow the instructions on this webpage to debug an app deployed to Kubernetes in Visual Studio 2019: https://github.com/VladimirAkopyan/DockerDotnetDebug. The instructions (in case the webpage is every brought down are as follows):
1) docker run -d -p 2222:2222 -p 5000:5000 clumsypilot/dotnetdebug:asp-debug-sample
2) Open Localhost:5000 and verify thee website is running.
3) Clone the Repo and open project DotnetDebug in VS2017
4) Setup a remote connection over SSH
5) Set a breakpoint in DebugSample/Pages/Index.cshtml.cs
6) Start debugger and reload page!
7) Alternatively, debug this container while it's running on a kubernetes cluster using
kubectl port-forward <POD-NAME> 2222
The instructions are described in more detail here: https://blog.quickbird.uk/debug-netcore-containers-remotely-9a103060b2ff
Steps 1-6 are clear and work very well. However, I am stuck on step 7. How do I deploy the container to Kubernetes and then port-forward the pod? I have tried this:
kubectl run my-app --image=clumsypilot/dotnetdebug:asp-debug-sample --port=5000
kubectl port-forward my-app-d664fc4c9-hw66j 2222
I then try to browse to: http://localhost:5000 and see this error:
SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u3 Protocol mismatch.
What am I doing wrong?
I cannot find any documentation that explains how to do this online so I am going to post an answer:
1) kubectl run my-app --image=clumsypilot/dotnetdebug:asp-debug-sample --port=5000
2) kubectl expose deployment my-app --type=LoadBalancer --port=8080 --target-port=5000 //not sure why you put my-app here and not the full app name i.e. my-app-d664fc4c9-k8s26 2222 in this case.
3) kubectl get pods //to get the pod name
4) kubectl port-forward my-app-d664fc4c9-k8s26 2222
Then I can browse to http://localhost:8080 in a web browser:
and the debugger stops when I load the homepage:
Attatch to process looks like this in Visual Studio:
Connect to Linux container like this:
The root password is in the dockerfile.
To start te instructions again:
1) Delete deployment: kubectl delete deployment my-app
2) Delete pod: kubectl delete pod my-app-d664fc4c9-t7ft9
3) Delete service: kubectl delete service my-app
To get the names use:
1) kubectl get deployment 2) kubectl get pod 3) kubectl get service