Amazon ec2 无自动缩放的ECS群集
我需要在不使用自动缩放的情况下创建ECS群集Amazon ec2 无自动缩放的ECS群集,amazon-ec2,aws-lambda,amazon-cloudformation,amazon-ecs,autoscaling,Amazon Ec2,Aws Lambda,Amazon Cloudformation,Amazon Ecs,Autoscaling,我需要在不使用自动缩放的情况下创建ECS群集 这是因为ASGs不支持专用主机(DH),即租约=主机。DH主要是为了节约成本,在某些情况下,因为即使我们不能使用ASG,节约也是值得的 我知道这可以通过使用宏和用Lambda备份的自定义资源或使用对流层在实例上循环来实现 但是,从任何相同或任何其他方法的示例开始,我们将非常感激 下面是我的appsec.yaml模板文件: AWSTemplateFormatVersion: 2010-09-09 Description: Provision Platf
这是因为ASGs不支持专用主机(DH),即租约=主机。DH主要是为了节约成本,在某些情况下,因为即使我们不能使用ASG,节约也是值得的 我知道这可以通过使用宏和用Lambda备份的自定义资源或使用对流层在实例上循环来实现 但是,从任何相同或任何其他方法的示例开始,我们将非常感激 下面是我的appsec.yaml模板文件:
AWSTemplateFormatVersion: 2010-09-09
Description: Provision Platform Container Service
Parameters:
PlatformCluster:
Type: String
PlatformClusterNotifications:
Type: String
PlatformClusterLifecycleNotification:
Type: String
Product:
Type: String
Environment:
Type: String
CDRevisionLoc:
Type: String
ClusterIdentifier:
Type: Number
ClusterMinSize:
Type: Number
ClusterMaxSize:
Type: Number
ClusterSubnets:
Type: List<AWS::EC2::Subnet::Id>
NodeImageId:
Type: AWS::EC2::Image::Id
NodeOSVolumeSize:
Type: Number
MinValue: 8
NodeInstanceRole:
Type: String
NodeInstanceProfile:
Type: String
NodeKeyName:
Type: AWS::EC2::KeyPair::KeyName
NodeInstanceType:
Type: String
NodeSecurityGroups:
Type: List<AWS::EC2::SecurityGroup::Id>
HanoverSchedule:
Type: String
Mappings:
InstanceStoreDevices:
"i3.2xlarge":
DEVS: "/dev/nvme0n1"
"i3.4xlarge":
DEVS: "/dev/nvme0n1 /dev/nvme1n1"
"i3.8xlarge":
DEVS: "/dev/nvme0n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1"
"m5d.2xlarge":
DEVS: "/dev/nvme1n1"
"m5d.4xlarge":
DEVS: "/dev/nvme1n1 /dev/nvme2n1"
"c5d.2xlarge":
DEVS: "/dev/nvme1n1"
"c5d.4xlarge":
DEVS: "/dev/nvme1n1"
"c5d.9xlarge":
DEVS: "/dev/nvme1n1"
Resources:
PlatformClusterLaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
configSets:
all: [install_cfn, update_ecs_agent, faro_self_install]
install_cfn:
files:
/etc/cfn/cfn-hup.conf:
content: !Sub |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
interval=5
mode: '000400'
owner: root
group: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
runas=root
triggers=post.update
path=Resources.PlatformClusterLaunchConfiguration.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource PlatformClusterLaunchConfiguration --configsets all --region ${AWS::Region}
mode: '000400'
owner: root
group: root
services:
sysvinit:
cfn-hup:
enabled: True
ensureRunning: True
files: [/etc/cfn/cfn-hup.conf, /etc/cfn/hooks.d/cfn-auto-reloader.conf]
update_ecs_agent:
commands:
update_agent:
command: yum update -y ecs-init
faro_self_install:
packages:
yum:
ruby: []
aws-cli: []
python27: []
python27-boto3: []
epel-release: []
unzip: []
ack: []
wget: []
jq: []
commands:
self_install:
command: !Sub |
#!/bin/bash
yum -y --security update
mkdir -p /etc/salt
cd $(mktemp -d)
REVNAME=$(basename ${CDRevisionLoc})
aws --region ${AWS::Region} s3 cp ${CDRevisionLoc} $REVNAME.zip
unzip -o $REVNAME.zip -d $REVNAME
chmod +x $REVNAME/install.sh
./$REVNAME/install.sh
Properties:
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: !Ref NodeOSVolumeSize
VolumeType: gp2
DeleteOnTermination: True
- DeviceName: /dev/xvdcz
VirtualName: ephemeral0
EbsOptimized: True
IamInstanceProfile: !Ref NodeInstanceProfile
ImageId: !Ref NodeImageId
InstanceMonitoring: True
InstanceType: !Ref NodeInstanceType
KeyName: !Ref NodeKeyName
SecurityGroups: !Ref NodeSecurityGroups
UserData:
Fn::Base64:
Fn::Sub:
- |
Content-Type: multipart/mixed; boundary="**"
MIME-Version: 1.0
--**
MIME-Version: 1.0
Content-Type: text/cloud-boothook; charset="us-ascii"
cloud-init-per once yum_update yum update -y
cloud-init-per once install_aws_cfn_bootstrap yum -y install aws-cfn-bootstrap
cloud-init-per instance custom_docker_options cat <<'EOF' > /etc/sysconfig/docker
DAEMON_MAXFILES=1048576
DAEMON_PIDFILE_TIMEOUT=10
OPTIONS="--default-ulimit nofile=1024:4096"
EOF
cloud-init-per instance custom_docker_storage_options cat <<'EOF' > /etc/sysconfig/docker-storage-setup
DEVS="${InstanceStoreDevices}"
STORAGE_DRIVER="devicemapper"
VG=docker
DATA_SIZE=99%FREE
AUTO_EXTEND_POOL=yes
LV_ERROR_WHEN_FULL=yes
EXTRA_DOCKER_STORAGE_OPTIONS="--storage-opt dm.fs=ext4 --storage-opt dm.use_deferred_deletion=true --storage-opt dm.basesize=20G"
EOF
cloud-init-per instance custom_ecs_options cat <<'EOF' > /etc/ecs/ecs.config
ECS_CLUSTER=${PlatformCluster}
ECS_ENABLE_TASK_IAM_ROLE=true
ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST=true
ECS_DISABLE_PRIVILEGED=true
ECS_AVAILABLE_LOGGING_DRIVERS=["json-file", "awslogs", "splunk"]
ECS_SELINUX_CAPABLE=false
ECS_APPARMOR_CAPABLE=false
ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION=10m
ECS_CONTAINER_STOP_TIMEOUT=1m
ECS_DISABLE_IMAGE_CLEANUP=false
ECS_IMAGE_CLEANUP_INTERVAL=30m
ECS_IMAGE_MINIMUM_CLEANUP_AGE=30m
ECS_NUM_IMAGES_DELETE_PER_CYCLE=50
ECS_UPDATES_ENABLED=false
ECS_DISABLE_METRICS=false
ECS_ENABLE_CONTAINER_METADATA=true
ECS_AWSVPC_ADDITIONAL_LOCAL_ROUTES=["169.254.120.120/32"]
EOF
--**
MIME-Version: 1.0
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
set -e
# set sysctl before doing anything
echo "net.ipv4.conf.all.forwarding = 1" >> /etc/sysctl.d/99-local.conf
sysctl net.ipv4.conf.all.forwarding=1
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource PlatformClusterLaunchConfiguration --configsets all --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource PlatformClusterASG --region ${AWS::Region}
- PlatformCluster: !Ref PlatformCluster
InstanceStoreDevices: !FindInMap [InstanceStoreDevices, !Ref NodeInstanceType, "DEVS"]
PlatformClusterASG:
Type: "AWS::AutoScaling::AutoScalingGroup"
DependsOn:
- PlatformClusterLaunchConfiguration
Properties:
Cooldown: 900
HealthCheckGracePeriod: 600
HealthCheckType: EC2
LaunchConfigurationName: !Ref PlatformClusterLaunchConfiguration
VPCZoneIdentifier: !Ref ClusterSubnets
MaxSize: !Ref ClusterMaxSize
MinSize: !Ref ClusterMinSize
DesiredCapacity: !Ref ClusterMinSize
MetricsCollection:
-
Granularity: 1Minute
NotificationConfigurations:
-
NotificationTypes:
- autoscaling:EC2_INSTANCE_LAUNCH_ERROR
- autoscaling:EC2_INSTANCE_TERMINATE_ERROR
TopicARN: !Ref PlatformClusterNotifications
TerminationPolicies:
- NewestInstance
Tags:
- Key: Name
Value: !Sub ${Product}${Environment}-pcs${ClusterIdentifier}
PropagateAtLaunch: true
- Key: Product
Value: !Ref Product
PropagateAtLaunch: true
- Key: Environment
Value: !Ref Environment
PropagateAtLaunch: true
- Key: Service
Value: !Sub gtn:${Environment}:pcs
PropagateAtLaunch: true
- Key: Schedule
Value: !Ref HanoverSchedule
PropagateAtLaunch: true
CreationPolicy:
ResourceSignal:
Timeout: PT20M
UpdatePolicy:
AutoScalingRollingUpdate:
WaitOnResourceSignals: True
PauseTime: PT20M
AutoScalingScheduledAction:
IgnoreUnmodifiedGroupSizeProperties: True
PlatformClusterTeardownLifecycleHook:
Type: "AWS::AutoScaling::LifecycleHook"
DependsOn:
- PlatformClusterASG
Properties:
AutoScalingGroupName: !Ref PlatformClusterASG
DefaultResult: ABANDON
HeartbeatTimeout: 900
LifecycleTransition: autoscaling:EC2_INSTANCE_TERMINATING
NotificationTargetARN: !Ref PlatformClusterLifecycleNotification
RoleARN: !Ref NodeInstanceRole
Outputs:
ECSAutoScalingGroup:
Value: !Ref PlatformClusterASG
AWST模板格式版本:2010-09-09
描述:提供平台容器服务
参数:
平台群集:
类型:字符串
平台俱乐部通知:
类型:字符串
平台群集生命周期化:
类型:字符串
产品:
类型:字符串
环境:
类型:字符串
CDRevisionLoc:
类型:字符串
群集标识符:
类型:编号
集群化:
类型:编号
ClusterMaxSize:
类型:编号
集群子网:
类型:列表
NodeImageId:
类型:AWS::EC2::Image::Id
节点体积大小:
类型:编号
最小值:8
节点安装角色:
类型:字符串
节点安装配置文件:
类型:字符串
NodeKeyName:
类型:AWS::EC2::KeyPair::KeyName
节点安装类型:
类型:字符串
节点安全组:
类型:列表
汉诺威时间表:
类型:字符串
映射:
InstanceStore设备:
“i3.2xlarge”:
开发者:“/dev/nvme0n1”
“i3.4XL”:
开发者:“/dev/nvme0n1/dev/nvme1n1”
“i3.8XL”:
开发者:“/dev/nvme0n1/dev/nvme1n1/dev/nvme2n1/dev/nvme3n1”
“m5d.2xlarge”:
开发者:“/dev/nvme1n1”
“m5d.4XL”:
开发者:“/dev/nvme1n1/dev/nvme2n1”
“c5d.2xlarge”:
开发者:“/dev/nvme1n1”
“c5d.4XL”:
开发者:“/dev/nvme1n1”
“c5d.9xlarge”:
开发者:“/dev/nvme1n1”
资源:
PlatformClusterLaunchConfiguration:
类型:AWS::AutoScaling::LaunchConfiguration
元数据:
AWS::CloudFormation::Init:
配置集:
全部:[安装\u cfn、更新\u ecs\u代理、faro\u自我安装]
安装\u cfn:
文件夹:
/etc/cfn/cfn-hup.conf:
内容:!潜艇|
[主要]
堆栈=${AWS::StackId}
region=${AWS::region}
间隔=5
模式:“000400”
所有者:root
组:根
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
内容:!潜艇|
[cfn自动装载机吊钩]
runas=根
触发器=post.update
path=Resources.PlatformClusterLaunchConfiguration.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn init-v--stack${aws::StackName}--resource PlatformClusterLaunchConfiguration--configsets all--region${aws::region}
模式:“000400”
所有者:root
组:根
服务:
sysvinit:
胡主席:
已启用:True
确保运行:正确
文件:[/etc/cfn/cfn-hup.conf,/etc/cfn/hooks.d/cfn auto-reloader.conf]
更新\u ecs\u代理:
命令:
更新\u代理:
命令:yum update-y ecs init
faro_self_安装:
包装:
百胜:
红宝石:[]
aws cli:[]
蟒蛇27:[]
蟒蛇27-boto3:[]
epel发布:[]
解压:[]
确认:[]
工作组:[]
jq:[]
命令:
自行安装:
命令:!潜艇|
#!/bin/bash
yum-y--安全更新
mkdir-p/etc/salt
cd$(mktemp-d)
REVNAME=$(basename${CDRevisionLoc})
aws—region${aws::region}s3 cp${CDRevisionLoc}$REVNAME.zip
解压-o$REVNAME.zip-d$REVNAME
chmod+x$REVNAME/install.sh
./$REVNAME/install.sh
特性:
块设备应用程序:
-设备名称:/dev/xvda
Ebs:
体积:!参考节点体积
卷类型:gp2
DeleteOnTermination:True
-设备名称:/dev/xvdcz
虚拟名称:转瞬即逝的0
EbsOptimized:对
IAMSInstanceProfile:!参考节点安装配置文件
图像ID:!Ref NodeImageId
实例监视:True
实例类型:!Ref节点安装类型
关键字:!Ref NodeKeyName
安全组:!Ref节点安全组
用户数据:
Fn::Base64:
Fn::Sub:
- |
内容类型:多部分/混合;边界=“**”
MIME版本:1.0
--**
MIME版本:1.0
内容类型:文本/云引导钩;charset=“us ascii”
每次云初始化yum\u更新yum更新-y
cloud init per once install_aws_cfn_bootstrap yum-y install aws cfn bootstrap
cloud init per instance custom_docker_options catASG只是使用指定的启动配置启动相同实例的一种方便方式
如果您获取了启动配置并使用它来加速实例,那么您基本上就切断了ASG
最后,您需要设置用户数据,以便将容器实例注册到集群中
看
有了它,您可以创建一个虚拟主机,并使用它来使用专用主机启动更多实例。然后,您可以使用Cloudwatch和Lambda构建一个穷人的ASG。我不是100%确定DH,但您可以通过将ECS_Cluster=your_Cluster_NAME
放在/etc/ECS/ECS.config
中(您可以在用户数据
脚本中执行)将您的实例锁定到ECS群集