Kubernetes检查是否“静音".吊舱完成执行 [英] Kubernetes check if "silent" pod finished executing

查看:89
本文介绍了Kubernetes检查是否“静音".吊舱完成执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我定义了一个Pod,该Pod仅运行一些代码,然后退出.我需要确保此Pod退出后才能运行其他Pod.实现此目的的最佳方法是什么?

Let's say that I defined a pod that simply runs a few pieces of code and exits afterwards. I need to make sure that this pod exits before allowing other pods to run. What is the best way to implement this?

我过去经常通过执行网络请求来检查Pod是否准备就绪.一旦准备好,一些webapps pod就会阻塞并监听预定义的端口,因此我可以让等待的pod对它们执行netcat请求.但是在这种特殊情况下,吊舱不需要打开任何端口,因此该方法不起作用.有人可以建议替代方法吗?

I used to check whether a pod is ready by performing network requests, e.g. once ready, some webapps pods will block and listen to pre-defined ports, hence I can have the waiting pods performing netcat requests to them. But in this particular case the pod does not need to open any port, hence this approach does not work. Can anyone suggest an alternative?

谢谢

推荐答案

如果需要在每个pod启动/重新启动中运行代码段",则您可能正在寻找

If the "pieces of code" needs to be run in every pod start/restart, you maybe are looking for an Init Container implementation:

初始化容器是在应用程序之前运行的专用容器 容器,可以包含不存在的实用程序或安装脚本 应用图片.

Init Containers are specialized Containers that run before app Containers and can contain utilities or setup scripts not present in an app image.

如果您的代码是多个Pod的依赖项,并且需要运行一次(例如,在每次新部署中运行),则可以考虑使用

If your code is a dependency for multiple pods and needs to be run once (e.g., on every new deploy), you may consider using a Job Controller, and implement a logic to check if it's completed before deploying new pods/containers. (You can use commands like kubectl wait --for=condition=complete job/myjob on your deploy script).

如果要使用头盔进行部署,最好的选择是将k8s作业与pre-installpre-upgrade组合使用

If you are using helm to deploy, the best option is to use k8s job combined with pre-install and pre-upgrade helm hooks.

这篇关于Kubernetes检查是否“静音".吊舱完成执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆