[英]getting a No such file or directory error with Kubernetes cronjob and dockerfile
我有一个要使用 dockerfile 运行的脚本,如下所示:
FROM debian:unstable-slim
RUN apt-get update && apt-get install -y netcat-traditional httpie postgresql-client
COPY go.sh /tmp/go.sh
WORKDIR /tmp
CMD ["bash", "-c", "/tmp/go.sh"]
它在本地工作正常,但我需要将它部署为 kubernetes cronjob,我有一个类似这样的配置文件:
script:
- docker build -t {github_enterprise_url/org/repo} .
并且构建 output 似乎还可以:
...
Step 3/7 : COPY go.sh /tmp/go.sh
---> ab8d5227f65e
...
Successfully built e79162d90def
对于 cronjob yaml,除其他外,我有这样的事情:
spec:
containers:
- image: >-
${ trigger.artifacts.?[type == 'docker'].?[name matches
'org/repo'].![reference][0] }
然后部署成功,但显示以下消息:
Cannot determine if job needs to be started: Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.
所以我尝试像这样手动运行它:
kubectl create job --from=cronjob/name name-manual-123
在查看创建的 pod 的日志时,我得到以下信息:
kubectl logs name-manual-123-ab1cd
bash: line 1: /tmp/go.sh: No such file or directory
任何线索?
/tmp
目录通常用于临时文件存储。 在此处安装 RAM 磁盘 ( tmpfs
) 很常见,并且 Kubernetes 设置可能会在您没有注意到的情况下执行此操作。
您可以通过将脚本存储在默认PATH
上的位置来解决此问题,例如/usr/local/bin
:
# /usr/local/bin, not /tmp
COPY go.sh /usr/local/bin
CMD ["go.sh"]
# will work when the script is executable; on $PATH (in /usr/local/bin);
# and has a correct shebang line
# #!/bin/sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.