Terraform:在 EKS/ECS 上部署 Docker Compose 应用程序 [英] Terraform: Deploying a Docker Compose app on EKS/ECS
问题描述
我使用一个开源服务器应用程序在 Docker Compose 上运行.它有一些服务,包括 PostgreSQL DB 和 Redis.
I use an open-source server application running on Docker Compose. It has a few services, including PostgreSQL DB and Redis.
如何使用 Terraform 在完整的 IaC 中最好地将此应用程序部署到 AWS?
ecs-cli
现在 支持 在 Amazon ECS 中发送 docker compose
配置.
ecs-cli
now supports sending docker compose
configs in Amazon ECS.
但是,我不认为它可以与 Terraform 工作流程集成(这可能不是什么大惊小怪).据我所知,ecs-cli
在 CloudFormation 中不受支持,根据 这个问题,目前仍然开放.所以我认为它也不能轻易添加到 Terraform.
However, I do not think it could be integrated with the Terraform workflow (which is maybe not a big fuss). What I know for sure is that ecs-cli
is not supported in CloudFormation, as per this issue, still open at this time. So I assume it cannot easily be added to Terraform either.
- 将您的
docker-compose.yml
文件转换为kubectl
YAML. - (准备在每次软件包升级时都这样做).
- 使用 Terraform 的 + EKS API 进行部署(最小的示例).
- Take your
docker-compose.yml
file, translate it tokubectl
YAML. - (Prepare to doing so every time the package upgrades).
- Deploy using Terraform's + EKS APIs (minimal example).
但这还不是完全的 IaC.每次 docker-compose 在源存储库中更改时,您都必须重新翻译配置.而且听起来工作量很大.
But that is not fully IaC yet. And you have to retranslate your config each time the docker-compose changes in the source repository. And it sounds like a lot of work.
- 为应用程序编写 Helm 图表.
- 运行 Terraform 以启动集群.
- 仍然使用
helm
运行 Terraform provider 在集群上使用 Helm 安装应用程序.
- Write a Helm chart for the application.
- Run Terraform to start a cluster.
- Still run Terraform with a
helm
provider to install the application with Helm on the cluster.
我读过 Kompose 可以自动将 Docker Compose 配置转换为 k8s 配置,但它们似乎没有移植到 AWS 上,不谈 Terraform.
I read Kompose can automagically translate a Docker Compose configuration to a k8s configuration, but they don't appear to be ported on AWS, not to talk about Terraform.
- 使用 Packer 构建自定义 EC2 AMI.
- 使用 Terraform,设置 DB、Redis 和所有权限/网络等.
- 使用自定义 AMI 启动 EC2 实例.
- AMI 包含(定制的)应用程序代码,尤其是
docker-compose.yml
.以及 Docker 镜像. - AMI 启动 Docker Compose
systemctl
服务.
- Build a custom EC2 AMI with Packer.
- Using Terraform, set up the DB, Redis and all permissions / network / etc.
- Start an EC2 instance with the custom AMI.
- The AMI contains (customized) application code, especially the
docker-compose.yml
. And the Docker images. - The AMI starts a Docker Compose
systemctl
service.
这会造成一些伤害:构建时间长、监控困难、无法扩展.
That would kind of hurt: long builds, difficult monitoring, no scaling.
- 我提到我需要完整的 IaC.我的意思是:
master
上的书面配置(并且只有它)会告诉您部署的内容.- 部署将完成,我的团队无需运行任何其他命令.它基本上适用于 CI/CD 或单次推送.
- 在 IaC 中可以轻松配置监控和警报.
- The written config (and it only) on
master
tells you what is deployed. - The deploy will complete without my team having to run any other command. It basically works either on CI/CD or on single-push'n'go.
- Monitoring and alerting are easily configured in the IaC.
推荐答案
1.拭目以待
谁知道,ecs-cli-v2
可能更好地与 CloudFormation 和/或 Terraform 集成.
1. Wait and See
Who knows, ecs-cli-v2
might be better integrated with CloudFormation and/or Terraform.
如问题中所述.可能是最好的解决方案,尽管需要(很少)努力来参数化 Helm.
As mentioned in the question. Probably the best solution, albeit requiring a (little) effort to parametrize Helm.
另见:Helm 入门.
Docker Swarm 现在接受来自docker-的输入compose.yml
文件.可以在此处找到并配置模板.配置完成后,可以将其集成到 Terraform 基础架构中.
Docker Swarm now accepts inputs from a docker-compose.yml
file. The template can be found and configured here. Once configured, it may be integrated to a Terraform infrastructure.
这个(3 岁)教程 解释了如何在 AWS 上使用 Docker Swarm 模式.
This (3-year old) tutorial explains how to use Docker Swarm mode on AWS.
要启动容器,如有必要(未完全调查,欢迎反馈),您可以使用 Terraform 的 local-exec
.这样你就可以通过 SSH 连接到主节点并运行 docker stack deploy
和其他类似的命令,同时仍然以 IaC 风格写下所有内容.
To launch the container, if necessary (not fully investigated, feedback is welcome), you could use Terraform's local-exec
. This way you can SSH into the master node and run docker stack deploy
and other similar commands, while still having all written down in IaC style.
这篇关于Terraform:在 EKS/ECS 上部署 Docker Compose 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!