在Jobs/Cron Jobs中主容器被终止后杀死Sidecar容器



我们正面临着在Jobs/Cron Jobs中出现sidecars的问题。我们使用EFK堆栈进行日志记录,并使用filebeat作为运输日志的侧车容器应用到ElasticSearch。但是,在批处理作业中实现这一点时,一旦主容器(主作业脚本)终止,sidecar容器就不会被杀死。所以约伯永远不会进入完成/终止状态。关于如何处理这个问题有什么建议吗?-在主容器终止后杀死sidecar容器

From https://carlosbecker.com/posts/k8s-sidecar-shutdown/

我仍然需要对此进行测试,但基本上您在容器之间拥有一个共享卷。主容器有一个带有陷阱的finally块,当它退出时触及文件。

则sidecar容器轮询该文件是否存在,当它存在时是否存在。

containers:
- name: agent
command: ["/bin/sh", "-c"]
args:
- |
trap 'touch /usr/share/pod/done' EXIT
buildkite-agent-entrypoint start 
--disconnect-after-job 
--disconnect-after-idle-timeout=50    
# ...
volumeMounts:
- mountPath: /usr/share/pod
name: tmp-pod
- name: dind
command: ["/bin/sh", "-c"]
args:
- | 
dockerd-entrypoint.sh &
while ! test -f /usr/share/pod/done; do
echo 'Waiting for the agent pod to finish...'
sleep 5
done
echo "Agent pod finished, exiting"
exit 0
# ...
volumeMounts:
- mountPath: /usr/share/pod
name: tmp-pod
readOnly: true
# ...
volumes:
- emptyDir: {}
name: tmp-pod
# ...

很恶心吧?希望1.28的一等侧斗容器为这种情况提供更好的支持

最新更新