running a linux command against a pid inside k8 pod

886 Views Asked by At

Is it possible to run a linux command against a process which is running inside a kubernetes pod. Example: I want to grab heapdumps on a java process running inside a k8 pod. The pod comes with minimal installation and does not have that much disk space either, so I want to run jmap command from local machine (pointing to k8 cluster). Thanks.

2

There are 2 best solutions below

0
Wytrzymały Wiktor On BEST ANSWER

As I have already mentioned in the comments, what you can use is the kubectl exec command:

Execute a command in a container.

Usage:

$ kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]

The kubectl exec command is a tool that allows you to inspect and debug your applications, by executing commands inside your containers.

If you need more details and examples regarding how to use it, I recommend these two guides:

0
colossal On

kubectl exec did it. It allows to run any command inside the container. For example:

kc exec <POD_NAME> -- jmap -dump:live,format=b,file=heapdump.bin <pid>