Terraform:在EKS/ECS上部署Docker Compose应用程序 [英] Terraform: Deploying a Docker Compose app on EKS/ECS

查看:388
本文介绍了Terraform:在EKS/ECS上部署Docker Compose应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个在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 现在

ecs-cli now supports sending docker compose configs in Amazon ECS.

但是,我不认为它可以与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.

  • Take your docker-compose.yml file, translate it to kubectl 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进行安装集群上具有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,设置数据库,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 .我的意思是:
  1. master上的书面配置(仅适用于配置)告诉您部署了什么.
  2. 部署将完成,而我的团队无需运行任何其他命令.它基本上可以在CI/CD上或在单推式操作中使用.
  3. 可以在IaC中轻松配置监视和警报.
  1. The written config (and it only) on master tells you what is deployed.
  2. 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.
  3. Monitoring and alerting are easily configured in the IaC.

  • 我希望将某些服务替换为AWS组件(即,RDS替换为PostgreSQL服务,而ElastiCache替换为Redis服务).
  • 该应用程序成为 Apache Superset .但是,我也想知道什么是解决Docker Compose问题的最佳通用方法.
  • I wish to replace some services with AWS components (namely, the PostgreSQL service by an RDS, and the Redis service with an ElastiCache).
  • The application happens to be Apache Superset. However I am also wondering what is considered the best general approach to this Docker Compose problem.
  • 推荐答案

    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屋!

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