Kubernetes集群和Phoenix-自动执行mix ecto.migrate吗? [英] Kubernetes cluster and Phoenix - automate `mix ecto.migrate`?

查看:87
本文介绍了Kubernetes集群和Phoenix-自动执行mix ecto.migrate吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的Phoenix应用程序推送到Kubernetes集群进行审查.我使用GitLab为Web服务器创建服务,并为临时Postgres Pod创建另一个服务.

I'm pushing my Phoenix app to a Kubernetes cluster for review. I use GitLab to create a service for the web server and another service for a temporary postgres pod.

我想做的是使mix ecto.createmix ecto.migrate自动化.但是,这存在时间问题-postgres服务器尚未准备就绪的时间很短.

What I would like to do is automate mix ecto.create and mix ecto.migrate. However, there is a timing issue - there's a short period of time when the postgres server is not ready yet.

在创建Web应用程序服务之前,我可以在部署脚本中轮询postgres服务.但这是最实用的方法吗?

I could poll the postgres service in my deployment script before creating the web application service. But is this the most practical method?

推荐答案

Kubernetes具有称为

Kubernetes has something called init containers which may help you.

在文档中,这是一个等待dB容器的应用容器示例.

From the documentation, here is an example of an app container which waits for a dB container.

apiVersion: v1 
kind: Pod 
metadata: 
  name: myapp-pod 
  labels: 
    app: myapp 
spec: 
  containers: 
  - name: myapp-container 
    image: busybox 
    command: ['sh', '-c', 'echo The app is running! && sleep 3600'] 
  initContainers: 
  - name: init-myservice 
    image: busybox 
    command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;'] 
  - name: init-mydb 
    image: busybox 
    command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;'] 

这篇关于Kubernetes集群和Phoenix-自动执行mix ecto.migrate吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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