简体   繁体   English

将单个配置文件挂载到 ECS 服务上

[英]Mount a single config file onto an ECS service

I come from a background in Kube.netes and I'm trying to learn AWS/ECS.我来自 Kube.netes 背景,我正在尝试学习 AWS/ECS。 In Kube.netes, you can use ConfigMap resources to mount simple one-off config files onto containers quickly and easily without having to go through all the trouble of setting up volumes.在 Kube.netes 中,您可以使用ConfigMap资源快速轻松地将简单的一次性配置文件挂载到容器中,而无需 go 设置卷的所有麻烦。 This also makes it very easy to configure services from Terraform, which is what I'm trying to do.这也使得从 Terraform 配置服务变得非常容易,这正是我正在尝试做的。

Do AWS ECS Services have a feature like the Kube.netes Config Maps? AWS ECS 服务是否具有 Kube.netes Config Maps 之类的功能? I just need the dead-simplest way to insert arbitrary text files into my services on startup, which can be updated with Terraform quickly.我只需要最简单的方法在启动时将任意文本文件插入到我的服务中,可以使用 Terraform 快速更新。 I want to avoid having to rebuild the whole image every time this file changes.我想避免每次此文件更改时都必须重建整个图像。

Is this possible or do I need to create volumes for this?这是可能的还是我需要为此创建卷? If so, what's the best type of volume configuration for this purpose?如果是这样,为此目的最好的卷配置类型是什么? I can store and update the files in S3 easily, and these are just simple config files that only need read access, so would this be an acceptable case to just mount the S3 bucket?我可以轻松地在 S3 中存储和更新文件,这些只是只需要读取访问权限的简单配置文件,那么仅挂载 S3 存储桶是否可以接受?

The solution depends on architecture and details.解决方案取决于架构和细节。 Here is some possible solutions that I can see:这是我可以看到的一些可能的解决方案:

  1. If possible to set parameters as environment variables, I recommend to store it values inside AWS Systems Manager or Secrets Manager services and pass to containers (In other way you may generate config file inside container reading these ENVs and print values to file by using custom Entrypoint )如果可以将参数设置为环境变量,我建议将其值存储在 AWS Systems ManagerSecrets Manager服务中并传递给容器(以其他方式,您可以在容器内生成配置文件,读取这些 ENV 并使用自定义Entrypoint值打印到文件)
  2. If you need to upload file inside docker container here is two possible simple solutions:如果您需要在 docker 容器内上传文件,这里有两种可能的简单解决方案:
    • Create a fixed base_image and every time rebuild only last layer of it.创建一个固定的base_image并且每次只重建它的最后一层。 In Dockerfile terms it will be look like:在 Dockerfile 术语中,它看起来像:
       FROM base_image COPY config_file /app/config_file
    • Store config file at S3 bucket and copy it on container start by changing Entrypoint .将配置文件存储在 S3 存储桶中,并通过更改Entrypoint将其复制到容器中。 For example if current Entryrpoint is /usr/bin/apache :例如,如果当前Entryrpoint/usr/bin/apache
       FROM some_image RUN echo 'aws s3 cp s3://mybucket/config_file /app/ && /usr/bin/apache' > /Entrypoint.sh ENTRYPOINT ['sh', '/Entrypoint.sh']
      *However you need to install aws cli inside container in this case. *但是在这种情况下你需要在容器中安装aws cli。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM