【问题标题】:How to configure Wordpress via AWS Fargate Container using AWS CDK如何使用 AWS CDK 通过 AWS Fargate 容器配置 Wordpress
【发布时间】:2020-06-10 04:26:14
【问题描述】:

我想使用 AWS CDK 在容器变体(即没有 EC2 实例)中通过 AWS Fargate 配置 Wordpress。

我已经为此目的实现了一个工作配置。但是,目前无法以这种形式安装主题或上传文件,因为 Wordpress 位于一个或多个 docker 容器中。

这是我当前的 cdk 实现:

AWS-CDK

export class WordpressWebsiteStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        // GENERAL

        const vpc = new ec2.Vpc(this, 'Vpc', {
            // 2 is minimum requirement for cluster
            maxAzs: 2,

            // only create Public Subnets in order to prevent aws to create
            // a NAT-Gateway which causes additional costs.
            // This will create 1 public subnet in each AZ.
            subnetConfiguration: [
                {
                    name: 'Public',
                    subnetType: ec2.SubnetType.PUBLIC,
                },
            ]
        });

        // DATABASE CONFIGURATION

        // Security Group used for Database
        const wordpressSg = new ec2.SecurityGroup(this, 'WordpressSG', {
            vpc: vpc,
            description: 'Wordpress SG',
        });

        // Database Cluster for wordpress database
        const dbCluster = new rds.DatabaseCluster(this, 'DBluster', {
            clusterIdentifier: 'wordpress-db-cluster',
            instances: 1,
            defaultDatabaseName: DB_NAME,
            engine: rds.DatabaseClusterEngine.AURORA, // TODO: AURORA_MYSQL?
            port: DB_PORT,
            masterUser: {
                username: DB_USER,
                password: cdk.SecretValue.plainText(DB_PASSWORD)
            },
            instanceProps: {
                instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
                vpc,
                securityGroup: wordpressSg,
            }
        });

        // FARGATE CONFIGURATION

        // ECS Cluster which will be used to host the Fargate services
        const ecsCluster = new ecs.Cluster(this, 'ECSCluster', {
            vpc: vpc,
        });

        // FARGATE CONTAINER SERVICE

        const fargateService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, 'WordpressFargateService', {
            cluster: ecsCluster, // Required
            desiredCount: 1, // Default is 1
            cpu: 512, // Default is 256
            memoryLimitMiB: 1024, // Default is 512

            // because we are running tasks using the Fargate launch type in a public subnet, we must choose ENABLED
            // for Auto-assign public IP when we launch the tasks.
            // This allows the tasks to have outbound network access to pull an image.
            // @see https://aws.amazon.com/premiumsupport/knowledge-center/ecs-pull-container-api-error-ecr/
            assignPublicIp: true,

            taskImageOptions: {
                image: ecs.ContainerImage.fromRegistry(wordpressRegistryName),
                environment: {
                    WORDPRESS_DB_HOST: dbCluster.clusterEndpoint.socketAddress,
                    WORDPRESS_DB_USER: DB_USER,
                    WORDPRESS_DB_PASSWORD: DB_PASSWORD,
                    WORDPRESS_DB_NAME: DB_NAME,
                },
            },
        });
        fargateService.service.connections.addSecurityGroup(wordpressSg);
        fargateService.service.connections.allowTo(wordpressSg, ec2.Port.tcp(DB_PORT));
    }
}

也许有人知道我如何通过CDK 设置Fargate,以便各个Wordpress 容器有一个共同的volume,然后数据位于该volume 上?或者也许有另一个优雅的解决方案:)

提前非常感谢:)


找到了解决办法????

感谢开放的GitHub-Issue 和提供的Gist 中的cmets,我终于能够配置一个可行的解决方案。

我在Gist 中提供了我当前的解决方案。所以请随意看看,留下一些 cmets 并根据您的问题进行调整。

【问题讨论】:

    标签: wordpress docker amazon-ecs aws-fargate


    【解决方案1】:

    我是 AWS 容器服务团队的一员,我想向您介绍一下我们所处的背景。我们最近(5/11/2020)宣布将 Amazon ECS / AWS Fargate 与 Amazon EFS(弹性文件系统)集成。这是让您实现您想要实现的目标的管道。你可以阅读更多关于理论herehere for a practical example

    我上面链接的示例使用 AWS CLI 只是因为 CloudFormation 对此功能的支持尚未发布(敬请期待)。一旦发布了 CFN 支持,CDK 就会接受它,届时,它将能够调整您的 CDK 代码以实现您想要的。

    【讨论】:

    • 很遗憾,这不是我想要阅读的信息?,但感谢您的回答!我将尝试以这种方式实现它。如果有人有其他解决方案,我会很乐意阅读。
    • 对此有任何进一步的细节吗?添加了支持,但示例严重缺乏,我无法让 EFS 挂载与 Fargate 管道中的 CDK 一起使用。一个多星期了,仍然无法正常工作。
    • 它只是挂起。我想我需要等待 2 小时,看看它是否会引发任何错误......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2021-11-17
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多