[英]Can we run an executable jar file inside an already running Kubernetes pod?
I need to execute a diagnostic program written for my application.我需要执行为我的应用程序编写的诊断程序。 The application is running/deployed in a Kubernetes pod.
该应用程序正在 Kubernetes pod 中运行/部署。 I want to copy a diagnostic executable jar file inside the Kubernetes pod and execute it without stopping the pod.
我想在 Kubernetes pod 中复制诊断可执行文件 jar 文件并在不停止 pod 的情况下执行它。 How can this be achieved?
如何做到这一点? Is there a specific way to run the executable jar using the Kubernetes pod environment in place?
有没有一种特定的方法可以使用 Kubernetes pod 环境运行可执行文件 jar?
You can try the kubectl cp
command:您可以尝试
kubectl cp
命令:
Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
将 /tmp/foo_dir 本地目录复制到默认命名空间中远程 pod 中的 /tmp/bar_dir
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
将 /tmp/foo 本地文件复制到特定容器中远程 pod 中的 /tmp/bar
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
将 /tmp/foo 本地文件复制到命名空间中远程 pod 中的 /tmp/bar
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
Copy /tmp/foo from a remote pod to /tmp/bar locally
将 /tmp/foo 从远程 pod 复制到本地 /tmp/bar
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.将可执行文件添加到容器中后,您可以
exec
进入 pod 并手动执行文件。
To open up interactive bash terminal打开交互式bash终端
kubectl exec <pod name> -n <namespace> -c <container name> -it bash
After this, find your executable jar and run it.在此之后,找到您的可执行文件 jar 并运行它。 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检查这个官方k8s页面https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.