How to Collect Memory Dumps for .NET Applications on Kubernetes

Somebody who likes to code
Search for a command to run...

Somebody who likes to code
No comments yet. Be the first to comment.
Google processes tens of thousands of code changes every day across a codebase of hundreds of millions of lines. The secret isn't magic tooling — it's a documented, principled approach to code review

Amazon Simple Notification Service (SNS) looks straightforward on the surface — publish a message, deliver it to subscribers — but the gap between a topic that "works in dev" and one that is productio

Amazon Simple Queue Service (SQS) is deceptively simple to get started with, but surprisingly easy to misconfigure in ways that cause silent message loss, runaway costs, duplicate processing storms, o

HTTP API is the right default choice for the majority of .NET serverless workloads. At 70% less cost than REST API, lower latency, and native JWT authorization, it covers most production requirements

AWS Lambda has become a cornerstone of modern serverless architectures, but writing a function that "just works" is very different from writing one that is performant, cost-effective, secure, and read

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-dumpglobal 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!