【问题标题】:CloudFormation AutoscalingGroup "LoadBalancer attachments did not stabilize"CloudFormation AutoscalingGroup“LoadBalancer 附件不稳定”
【发布时间】:2017-06-25 06:58:08
【问题描述】:

所以我正在使用 ECS(通过 ecs-cli 创建)和 CloudFormation,但在创建自动缩放组时遇到了问题:

它始终无法显示“LoadBalancer 附件不稳定”。有谁知道是什么原因造成的??

我有两个 CloudFormation 堆栈,一个主要用于设置我的大部分基础架构,第二个(出现故障)用于第二个 ECS 集群。我正在从第一个/主堆栈的输出中传递输入参数。

我认为这可能是子网大小问题(它们在第一个堆栈中创建并传递到第二个堆栈,10.0.0.0/24 和 10.0.1.0/24),所以我尝试在第二个cloudformation模板并使用它们,但它导致了同样的错误。

Autoscaling 组和 ELB 在两个模板文件之间创建相同...

第一堆:

"InternetGateway": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::InternetGateway"
    },
    "AttachGateway": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::VPCGatewayAttachment",
        "Properties": {
            "VpcId": {
                "Ref": "Vpc"
            },
            "InternetGatewayId": {
                "Ref": "InternetGateway"
            }
        }
    },
    "RouteViaIgw": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::RouteTable",
        "Properties": {
            "VpcId": {
                "Ref": "Vpc"
            }
        }
    },
    "PublicRouteViaIgw": {
        "Condition": "CreateVpcResources",
        "DependsOn": "AttachGateway",
        "Type": "AWS::EC2::Route",
        "Properties": {
            "RouteTableId": {
                "Ref": "RouteViaIgw"
            },
            "DestinationCidrBlock": "0.0.0.0/0",
            "GatewayId": {
                "Ref": "InternetGateway"
            }
        }
    },
    "PubSubnet1RouteTableAssociation": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::SubnetRouteTableAssociation",
        "Properties": {
            "SubnetId": {
                "Ref": "PubSubnetAz1"
            },
            "RouteTableId": {
                "Ref": "RouteViaIgw"
            }
        }
    },
    "PubSubnet2RouteTableAssociation": {
        "Condition": "CreateVpcResources",
        "Type": "AWS::EC2::SubnetRouteTableAssociation",
        "Properties": {
            "SubnetId": {
                "Ref": "PubSubnetAz2"
            },
            "RouteTableId": {
                "Ref": "RouteViaIgw"
            }
        }
    },
"Outputs": {
    "VpcId": {
        "Value": { "Ref": "Vpc" }
    },
    "KeyName": {
        "Value": { "Ref": "KeyName" }
    },
    "SourceCidr": {
        "Value": { "Ref": "SourceCidr"}
    },
    "EcsInstancePolicy": {
        "Value": { "Ref": "EcsInstancePolicy" }
    },
    "SubnetIds": {
        "Value": { 
            "Fn::Join": [
                ",", [{
                        "Ref": "PubSubnetAz1"
                    },
                    {
                        "Ref": "PubSubnetAz2"
                    }
                ]
            ]
        }
    },
    "CloudSecurityGroup": {
        "Value": { "Ref": "EcsSecurityGroup" }
    },
    "GatewayRouteTable": {
        "Value": { "Ref": "PublicRouteViaIgw" }
    }
}

第二堆:

"Parameters": {
    "EcsAmiId": {
        "Type": "String",
        "Description": "ECS EC2 AMI id",
        "Default": ""
    },
    "EcsInstanceType": {
        "Type": "String",
        "Description": "ECS EC2 instance type",
        "ConstraintDescription": "must be a valid EC2 instance type."
    },
    "KeyName": {
        "Type": "AWS::EC2::KeyPair::KeyName",
        "Description": "Required - Name of an existing EC2 KeyPair to enable SSH access to the ECS instances"
    },
    "VpcId": {
        "Type": "String",
        "Description": "Required - VPC Id of existing VPC of Central stack.",
        "AllowedPattern": "^(?:vpc-[0-9a-f]{8}|)$",
        "ConstraintDescription": "VPC Id must begin with 'vpc-'"
    },
    "SubnetIds": {
        "Type": "String",
        "Description": "Required - Comma separated list of two (2) existing VPC Subnet Ids where ECS instances will run."
    },
    "AsgMaxSize": {
        "Type": "Number",
        "Description": "Maximum size and initial Desired Capacity of ECS Auto Scaling Group",
        "Default": "1"
    },
    "SourceCidr": {
        "Type": "String",
        "Description": "Required - Input CIDR/IP range to open up for ECS and Aurora"
    },
    "EcsInstancePolicy": {
        "Type": "String",
        "Description": "Required - IAM Policy for the ECS instances to use"
    },
    "EcsCluster": {
        "Type": "String",
        "Description": "ECS Cluster Name",
        "Default": "default"
    },
    "CloudSecurityGroup": {
        "Type": "String",
        "Description": "Name of the security group used by the ECS instances in the Cloud cluster"
    },
},
"Resources": {
    "EcsSecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupDescription": "ECS Allowed Ports",
            "VpcId": { "Ref": "VpcId" },
            "SecurityGroupIngress": [
                {
                    "IpProtocol": "tcp",
                    "FromPort": 22,
                    "ToPort": 22,
                    "SourceSecurityGroupId": { "Ref": "CloudSecurityGroup" }
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": 11000,
                    "ToPort": 11001,
                    "SourceSecurityGroupId": { "Ref": "CloudSecurityGroup" }
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": 22,
                    "ToPort": 22,
                    "CidrIp": { "Ref": "SourceCidr" }
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": 11000,
                    "ToPort": 11001,
                    "CidrIp": { "Ref": "SourceCidr" }
                }
            ]
        }
    },
    "EcsSecurityGroupIngressSelf": {
        "Type": "AWS::EC2::SecurityGroupIngress",
        "Properties": {
            "GroupId": { "Ref": "EcsSecurityGroup" },
            "SourceSecurityGroupId": { "Ref": "EcsSecurityGroup" },
            "IpProtocol": "tcp",
            "FromPort": 22,
            "ToPort": 9999
        }
    },
    "ElasticLoadBalancer": {
        "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
        "Properties": {
            "Subnets": {
                "Fn::Split": [
                    ",",
                    { "Ref": "SubnetIds" }
                ]
            },
            "CrossZone": "true",
            "SecurityGroups": [{
                "Ref": "EcsSecurityGroup"
            }],
            "Listeners": [{
                    "LoadBalancerPort": "22",
                    "InstancePort": "22",
                    "Protocol": "TCP"
                },
                {
                    "LoadBalancerPort": "11000",
                    "InstancePort": "11000",
                    "Protocol": "TCP"
                },
                {
                    "LoadBalancerPort": "11001",
                    "InstancePort": "11001",
                    "Protocol": "TCP"
                }
            ],
            "HealthCheck": {
                "HealthyThreshold": "2",
                "Interval": "30",
                "Target": "TCP:22",
                "Timeout": "5",
                "UnhealthyThreshold": "5"
            }
        }
    },
    "EcsInstanceProfile": {
        "Type": "AWS::IAM::InstanceProfile",
        "Properties": {
            "Path": "/",
            "Roles": [{
                "Ref": "EcsInstancePolicy"
            }]
        }
    },
    "EcsInstanceLc": {
        "Type": "AWS::AutoScaling::LaunchConfiguration",
        "Properties": {
            "ImageId": {
                "Ref": "EcsAmiId"
            },
            "InstanceType": {
                "Ref": "EcsInstanceType"
            },
            "AssociatePublicIpAddress": true,
            "IamInstanceProfile": {
                "Ref": "EcsInstanceProfile"
            },
            "KeyName": {
                "Ref": "KeyName"
            },
            "SecurityGroups": [{
                "Ref": "EcsSecurityGroup"
            }],
            "UserData": {
                "Fn::Base64": {
                    "Fn::Join": [
                        "", [
                            "#!/bin/bash\n",
                            "echo ECS_CLUSTER=",
                            {
                                "Ref": "EcsCluster"
                            },
                            " >> /etc/ecs/ecs.config\n"
                        ]
                    ]
                }
            }
        }
    },
    "EcsInstanceAsg": {
        "Type": "AWS::AutoScaling::AutoScalingGroup",
        "Properties": {
            "VPCZoneIdentifier": [{ "Ref": "SubnetIds" }],
            "LaunchConfigurationName": {
                "Ref": "EcsInstanceLc"
            },
            "MinSize": "1",
            "MaxSize": {
                "Ref": "AsgMaxSize"
            },
            "DesiredCapacity": {
                "Ref": "AsgMaxSize"
            },
            "LoadBalancerNames": [{ "Ref": "ElasticLoadBalancer" }],
            "Tags": [{
                "Key": "Name",
                "Value": {
                    "Fn::Join": [
                        "", [
                            "ECS Instance - ",
                            {
                                "Ref": "AWS::StackName"
                            }
                        ]
                    ]
                },
                "PropagateAtLaunch": "true"
            }]
        }
    },

如果有任何额外的信息会有所帮助,请告诉我

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-elb autoscaling


    【解决方案1】:

    从您的屏幕截图中,CloudFormation 堆栈和 EcsInstanceAsg Auto Scaling 组似乎是先前创建的,您正在尝试更新 Auto Scaling 组以引用新创建的负载均衡器。

    CloudFormation 资源无法稳定更新的最常见问题是由于引用的资源在 CloudFormation 堆栈之外被修改和/或删除。这会导致 CloudFormation 修改它无法再找到的资源,这可能会导致随机错误或超时,并且根据 AWS CloudFormation Best Practices 不鼓励这样做。如果是这种情况,最好的方法是尽可能使用全新的堆栈重新开始。

    如果您不是这种情况,则可能存在未知的限制或问题,即在 AWS::AutoScaling::AutoScalingGroup 中对 LoadBalancerNames 属性的就地更新(仅支持对该属性的就地更新 @987654323 @,所以它可能仍然存在问题)。尝试重新创建您的 Auto Scaling 组(更改模板中 EcsInstanceAsg 资源的名称会导致重新创建它),看看是否能解决问题。

    【讨论】:

      【解决方案2】:

      我让它工作了。解决方案是我所做的以下两项更改中的一项(或两项):

      1. 我意识到我没有为 ecs-cli 指定 VPC 以在现有 VPC 中启动集群。我更改了代码以在“ecs-cli up”调用中包含“--vpc”和“--subnets”选项。这可能是关键,因为as the documentation says, updating the VPCZoneIdentifier replaces the instances in the ASG, but not the ASG itself.

      2. 我删除了 AutoScalingGroup 的“VPCZoneIdentifier”参数周围的方括号,所以它现在看起来像这样: "VPCZoneIdentifier": { "Ref": "SubnetIds" },其中 SubnetIds 是两个子网 id 的字符串,它们之间用逗号分隔。 (请注意,截至 2017 年 2 月 7 日,The documentation is wrong。它说这个参数需要一个字符串列表,但显然不是。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-21
        • 2019-05-23
        • 2014-01-07
        • 2017-08-11
        • 2017-11-10
        • 2019-03-29
        • 2017-06-20
        • 2022-07-08
        相关资源
        最近更新 更多