等待其他部署开始运行,然后再创建其他部署? [英] wait for other deployments to start running before other can be created?

查看:102
本文介绍了等待其他部署开始运行,然后再创建其他部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用REST API创建部署/服务.我发送带有包含JSON对象的正文的POST请求,该JSON对象在Openshift上创建应用程序.在调用所有API之后,这些对象将被实例化.

I am creating the deployments/services using REST APIs. I send POST request with bodies which contain the JSON objects which create the applications on Openshift. After I call all the APIs, these objects get instantiated.

我有2个部署依赖于mongodb部署,但是此mongodb开始运行需要花费更长的时间,而这两个依赖于mongodb的部署则较早开始运行.由于mongodb连接失败(因为尚未建立连接),因此这会破坏2个部署中的代码.

I have 2 deployments which are dependent on mongodb deployment but this mongodb takes a little longer to start running, while the two deployments which are dependent on mongodb start running earlier. This breaks the code inside the 2 deployments as the mongodb connection fails(since it is not up yet).

可能有两种方法可以解决此问题.

There could be 2 possible way I can fix this problem.

  1. 在创建mongodb部署后,我延迟了一段时间,然后递归调用API以检查其状态是否在运行.

  1. I put a delay after i create mongodb deployment and recursively call the API to check it's status if it is running or not.

就像我们在docker-compose中使用键进行依赖一样进行更改,它告诉docker-compose首先应启动所有依赖项,然后再启动依赖项容器.

Just like we make changes in docker-compose, with the key, depends-on which tell the docker-compose that all the dependencies should be started first and then the dependent container.

在openshift中有什么方法可以实现吗?

Is there any way this could be achieved in openshift?

推荐答案

使用Kubernetes的运行状况检查机制代替实现复杂的逻辑来进行依赖项处理.如果您的应用程序启动但看不到Mongo DB,请使其崩溃.在Mongo DB联机之前,Kubernetes将继续重新启动它,并且您的应用程序将正常运行并可以正常运行. Kubernetes不会将流量发送到尚不健康的实例.

Instead of implementing complex logic for dependency handling, use health checking mechanism of Kubernetes. If your application starts and doesn't see Mongo DB, let it crash. Kubernetes will keep restarting it until Mongo DB comes online, and your application becomes healthy and serving as well. Kubernetes won't send traffic to not yet healthy instances.

文档: https://kubernetes.io /docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

这篇关于等待其他部署开始运行,然后再创建其他部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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