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.
Asked
Active
Viewed 671 times
0
-
1Have you tried to use [kubectl exec](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec)? – Wytrzymały Wiktor Nov 09 '20 at 09:44
2 Answers
0
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>

colossal
- 529
- 1
- 5
- 22
0
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:
Get a Shell to a Running Container: This page shows how to use
kubectl exec
to get a shell to a running container.

Wytrzymały Wiktor
- 11,492
- 5
- 29
- 37