[英]Kubectl Java client returns exit code 3 when using exec
I am writing a little backup programm for an application.我正在为应用程序编写一个小备份程序。 This will run as a CronJob within my k8s cluster.
这将在我的 k8s 集群中作为 CronJob 运行。 At one point, it should trigger an mysql dump on the database inside another pod.
在某一时刻,它应该在另一个 pod 内的数据库上触发 mysql 转储。
My code:我的代码:
Exec exec = new Exec();
Process process = exec.exec(
"default",
"database-pod",
new String[]{"sh", "-c", ""mysqldump -u {{user}} --p={{password}} schema > dbdump.sql",
false,
tty
);
process.waitFor();
process.destroy();
int exitValue = process.exitValue();
process.exitValue() always contains 3 + the mysql dump file is created, but does not contain any sql statements. process.exitValue() 始终包含 3 + mysql 转储文件已创建,但不包含任何 sql 语句。 Does somebody have a clue what I am doing wrong?
有人知道我做错了什么吗?
The base image of my backup programm is gcr.io/distroless/java:11 if that helps and was built using Jib我的备份程序的基本映像是 gcr.io/distroless/java:11 如果有帮助并且是使用Jib构建的
So after a bit of reading I figured out what was going wrong.因此,经过一番阅读,我发现出了什么问题。 Instead of writing --p I should have used --password all along
而不是写 --p 我应该一直使用 --password
When kubectl exec
(or oc exec
command) returns non-zero exit code, you should manually connect to the pod, and execute the same command directly, to inspect what's wrong:当
kubectl exec
(或oc exec
命令)返回非零退出代码时,您应该手动连接到 pod,并直接执行相同的命令,以检查问题所在:
[my-host]$ kubectl exec ${pod-id} -n ${namespace} bash -ti
[root@my-pod]# command...
# print command exit code (should be the same as before)
[root@my-pod]# echo $?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.