gpt4 book ai didi

docker - 如何在kubernetes中将 `args`作为 `command`运行

转载 作者:行者123 更新时间:2023-12-02 12:32:47 25 4
gpt4 key购买 nike

我有一个要在kubernetes作业中运行的python脚本。我已经使用configMap将其上传到位于dir/script.py中的容器中。

容器可以使用args["load"]正常运行。

我尝试在Job list 中使用postStart生命周期,但它似乎无法运行。

        lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- /usr/bin/python /opt/config-init/db/tls_generator.py

以下是 list 的摘要
      containers:
- name: {{ template "gluu.name" . }}-load
image: gluufederation/config-init:4.0.0_dev
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- /usr/bin/python /opt/config-init/db/tls_generator.py
volumeMounts:
- mountPath: /opt/config-init/db/
name: {{ template "gluu.name" . }}-config
- mountPath: /opt/config-init/db/generate.json
name: {{ template "gluu.fullname" . }}-mount-gen-file
subPath: generate.json
- mountPath: /opt/config-init/db/tls_generator.py
name: {{ template "gluu.fullname" . }}-tls-script
envFrom:
- configMapRef:
name: {{ template "gluu.fullname" . }}-config-cm
args: [ "load" ]

如何在 tls_generator.py之后运行 args["load"] scipt。

dockerFile部分看起来像
ENTRYPOINT ["tini", "-g", "--", "/app/scripts/entrypoint.sh"]
CMD ["--help"]

最佳答案

您正在使用Container Lifecycle Hooks,更具体地说PreStop

This hook is called immediately before a container is terminated due to an API request or management event such as liveness probe failure, preemption, resource contention and others.



如果要在 pod启动时执行命令,则应考虑使用 PostStart

This hook executes immediately after a container is created. However, there is no guarantee that the hook will execute before the container ENTRYPOINT. No parameters are passed to the handler.



另一种选择是使用 Init Containers,这是一些带有示例的想法:

  • Wait for a Service to be created, using a shell one-line command like:
 for i in {1..100}; do sleep 1; if dig myservice; then exit 0; fi; done; exit 1
  • Register this Pod with a remote server from the downward API with a command like:
curl -X POST http://$MANAGEMENT_SERVICE_HOST:$MANAGEMENT_SERVICE_PORT/register -d >'instance=$(<POD_NAME>)&ip=$(<POD_IP>)'
  • Wait for some time before starting the app container with a command like
sleep 60


请阅读有关如何使用 Init containers的文档以获取更多详细信息。

关于docker - 如何在kubernetes中将 `args`作为 `command`运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57588505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com