简体   繁体   English

使用 Kubernetes cronjob 和 dockerfile 得到 No such file or directory 错误

[英]getting a No such file or directory error with Kubernetes cronjob and dockerfile

I have a script that I want to run using a dockerfile that looks like this:我有一个要使用 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"]

It works fine on local, but I need to deploy it as a kubernetes cronjob, I have a config file with something like this:它在本地工作正常,但我需要将它部署为 kubernetes cronjob,我有一个类似这样的配置文件:

script:
- docker build -t {github_enterprise_url/org/repo} .

And the build output seems ok:并且构建 output 似乎还可以:

...
Step 3/7 : COPY go.sh /tmp/go.sh
 ---> ab8d5227f65e
...
Successfully built e79162d90def

And for the cronjob yaml, among other things, I have something like this:对于 cronjob yaml,除其他外,我有这样的事情:

spec:
  containers:
    - image: >-
        ${ trigger.artifacts.?[type == 'docker'].?[name matches
        'org/repo'].![reference][0] }

the deploy then succeded but with this message:然后部署成功,但显示以下消息:

Cannot determine if job needs to be started: Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.

So I tried to run it manually like this:所以我尝试像这样手动运行它:

kubectl create job --from=cronjob/name name-manual-123

And when looking at the logs for the pod created, I get this:在查看创建的 pod 的日志时,我得到以下信息:

kubectl logs name-manual-123-ab1cd
bash: line 1: /tmp/go.sh: No such file or directory

any clue?任何线索?

The /tmp directory is generally intended for temporary file storage. /tmp目录通常用于临时文件存储。 It's common to mount a RAM disk ( tmpfs ) there, and it's possible the Kubernetes setup does this without you noticing it.在此处安装 RAM 磁盘 ( tmpfs ) 很常见,并且 Kubernetes 设置可能会在您没有注意到的情况下执行此操作。

You can address this by storing your script in a location that's on the default PATH , like /usr/local/bin :您可以通过将脚本存储在默认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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM