Skip to main content

Command Palette

Search for a command to run...

How to Collect Memory Dumps for .NET Applications on Kubernetes

Updated
2 min read
How to Collect Memory Dumps for .NET Applications on Kubernetes

Some time ago, we published an article about dotnet-monitor and how to collect diagnostic data from applications running in a Kubernetes cluster. But what if you didn't follow that guideline and now need to collect diagnostic data, like a memory dump, to troubleshoot an issue in our application? Luckily, tools like dotnet-dump and some manual steps can help us achieve that.

The dotnet-dump global tool is a way to collect and analyze dumps on Windows, Linux, and macOS without any native debugger involved.

First, download the tool to your local machine. Then, copy the downloaded file to the pod using the following command (assuming we are in the folder containing the file):

kubectl cp ./dotnet-dump "MY_POD_NAME:/tmp/dotnet-dump" --namespace MY_NAMESPASE

Access the pod by running the command:

kubectl exec -it "pod/MY_POD_NAME" --namespace MY_NAMESPASE --sh

Once inside the pod, navigate to the tmp folder:

cd /tmp

Change the file permissions with this command:

chmod 777 ./dotnet-dump

Proceed to collect the memory dump by running this command:

./dotnet-dump collect -p 1

Wait until the memory dump is complete, then exit the pod using the command exit. The collected memory dump will be saved in the format core_yyyyMMdd_hhmmss. To copy the file from the pod to your local machine, use the following command:

kubectl cp "MY_POD_NAME:/tmp/core_20250109_110027" ./core_20250109_110027.DMP --namespace MY_NAMESPASE

That's it! We are now ready to analyze the memory dump on our local machine. Thank you, and happy coding!

More from this blog

raulnq

170 posts

Somebody who likes to code