Can we run an executable jar file inside an already running Kubernetes pod? Can we run an executable jar file inside an already running Kubernetes pod? kubernetes kubernetes

Can we run an executable jar file inside an already running Kubernetes pod?


You can try the kubectl cp command:

From the docs:

Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod inthe default namespace

kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir

Copy /tmp/foo local file to /tmp/bar in a remote pod in a specificcontainer

kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>

Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace

kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar

Copy /tmp/foo from a remote pod to /tmp/bar locally

kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

Once the executable is added inside the container, you can exec into the pod and execute the file manually.


To open up interactive bash terminal

kubectl exec <pod name> -n <namespace> -c <container name> -it bash

After this, find your executable jar and run it. once completed, exit the terminal.

You can run it directly.

kubectl exec <podname> -n <namespace> -c <container name> -- < command to run your jar > 

check this official k8s page https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec