forked from thefactory/cloudformation-mesos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesos-slave.json
More file actions
243 lines (221 loc) · 8.33 KB
/
mesos-slave.json
File metadata and controls
243 lines (221 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Launches a Docker-based Mesos Slave cluster",
"Parameters" : {
"InstanceAmi" : {
"Description" : "Mesos AMI",
"Type" : "String"
},
"InstanceType" : {
"Description" : "EC2 instance type",
"Type" : "String",
"Default" : "m1.small",
"AllowedValues" : ["m1.small","m1.medium","m1.large","m1.xlarge","m3.medium","m3.large","m3.xlarge","m3.2xlarge","c1.medium","c1.xlarge","c3.large","c3.xlarge","c3.2xlarge","c3.4xlarge","c3.8xlarge","cc2.8xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","r3.large","r3.xlarge","r3.2xlarge","r3.4xlarge","r3.8xlarge","cr1.8xlarge","hi1.4xlarge","hs1.8xlarge","i2.xlarge","i2.2xlarge","i2.4xlarge","i2.8xlarge","t1.micro","cg1.4xlarge","g2.2xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "String"
},
"ClusterId" : {
"Description" : "Mesos cluster ID",
"Type" : "String"
},
"ClusterSize" : {
"Description" : "Number of nodes to launch",
"Type" : "Number"
},
"ExhibitorDiscoveryUrl" : {
"Description" : "Exhibitor URL that returns active ZooKeeper nodes ('getCluster') (e.g., http://<exhibitor_node>/exhibitor/v1/cluster/list)",
"Type" : "String"
},
"ZkClientSecurityGroup" : {
"Description" : "Security group ID for ZK clients (should grant access to ZK nodes)",
"Type" : "String"
},
"MesosMasterSecurityGroup" : {
"Description" : "Security group ID of Mesos Master nodes",
"Type" : "String"
},
"DockerCredentials" : {
"Description" : "JSON string to be saved as .dockercfg",
"Type" : "String",
"Default" : "{}"
},
"LogstashConfig" : {
"Description" : "(optional) Config string for Logstash (to read task logs, you can use 'input { file { path => \"/tmp/mesos/slaves/*/frameworks/*/executors/*/runs/latest/stdout\" }')",
"Type" : "String",
"Default" : ""
},
"AdminSecurityGroup" : {
"Description" : "Existing security group that should be granted administrative access to Mesos (e.g., 'sg-123456')",
"Type": "String"
},
"Subnets" : {
"Description" : "List of VPC subnet IDs for the cluster",
"Type" : "CommaDelimitedList"
},
"VpcId" : {
"Description" : "VPC associated with the provided subnets",
"Type" : "String"
}
},
"Conditions" : {
"EnableLogstashCondition" : { "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "LogstashConfig" }, ""] }] }
},
"Resources" : {
"IAMUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"Policies" : [{
"PolicyName" : "IAMAccess",
"PolicyDocument" : {
"Statement" : [{
"Effect" : "Allow",
"NotAction" : "iam:*",
"Resource" : "*"
}]
}
}]
}
},
"HostKeys" : {
"Type" : "AWS::IAM::AccessKey",
"Properties" : {
"UserName" : { "Ref" : "IAMUser" }
}
},
"ServerGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : { "Fn::GetAZs" : "" },
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"MinSize" : "1",
"MaxSize" : "9",
"DesiredCapacity" : { "Ref" : "ClusterSize" },
"VPCZoneIdentifier" : { "Ref" : "Subnets" },
"Tags" : [
{
"Key" : "role",
"Value" : "mesos-slave",
"PropagateAtLaunch" : "true"
}
]
}
},
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config": {
"files" : {
"/usr/local/bin/zk-list-nodes" : {
"content" : { "Fn::Join" : ["", [
"#!/bin/bash -e\n",
"curl -s {{zk_discovery_url}} | python -c '",
"import sys, json;",
"j=json.load(sys.stdin);",
"servers=[\":\".join([s, str(j[\"port\"])]) for s in j[\"servers\"]];",
"print \",\".join(servers)'"
]]},
"context" : {
"zk_discovery_url" : { "Ref" : "ExhibitorDiscoveryUrl" }
},
"mode" : "000755",
"owner" : "root",
"group" : "root"
},
"/usr/local/bin/configure-mesos-slave" : {
"content" : { "Fn::Join" : ["\n", [
"#!/bin/bash -e",
"echo \"zk://`zk-list-nodes`/{{mesos_cluster_id}}\" > /etc/sv/mesos-slave/env/MESOS_MASTER",
"echo \"`ec2metadata --public-hostname`\" > /etc/sv/mesos-slave/env/MESOS_HOSTNAME"
]]},
"context" : {
"mesos_cluster_id": { "Ref": "ClusterId" }
},
"mode" : "000755",
"owner" : "root",
"group" : "root"
},
"/etc/cron.d/mesos": {
"content" : { "Fn::Join" : ["\n", [
"# Refresh mesos config every minute, but don't restart",
"* * * * * root /usr/local/bin/configure-mesos-slave"
]]},
"mode" : "000644",
"owner" : "root",
"group" : "root"
},
"/root/.dockercfg": {
"content" : { "Ref" : "DockerCredentials" },
"mode" : "000600",
"owner" : "root",
"group" : "root"
}
}
}
}
},
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : { "Ref" : "InstanceAmi" },
"SecurityGroups" : [ { "Ref" : "SecurityGroup" }, { "Ref" : "ZkClientSecurityGroup" }, { "Ref" : "AdminSecurityGroup" } ],
"AssociatePublicIpAddress": "true",
"InstanceType" : { "Ref" : "InstanceType" },
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -ex\n",
"# Helper function\n",
"function error_exit\n",
"{\n",
" cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
" exit 1\n",
"}\n",
"# Process CloudFormation init definitions\n",
"cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r LaunchConfig ",
" --access-key ", { "Ref" : "HostKeys" },
" --secret-key ", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]},
" --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",
{ "Fn::If" : [
"EnableLogstashCondition",
{ "Fn::Join" : ["", [
"echo '", { "Ref" : "LogstashConfig" },"' > /opt/logstash/logstash.conf\n",
"runit-service create logstash '/opt/logstash/bin/logstash -f /opt/logstash/logstash.conf'\n",
"echo '/root' > /etc/sv/logstash/env/HOME\n",
"runit-service enable logstash\n"
]]},
""
]},
"# Configure, enable, and start mesos-slave\n",
"configure-mesos-slave\n",
"runit-service enable mesos-slave\n",
"# All is well so signal success\n",
"cfn-signal -e 0 -r \"Stack setup complete\" '", { "Ref" : "WaitHandle" }, "'\n",
"#EOF"
]]}}
}
},
"SecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH, Mesos, and Marathon access",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress" :
[ { "IpProtocol" : "tcp", "FromPort" : "5051", "ToPort" : "5051", "SourceSecurityGroupId" : { "Ref" : "MesosMasterSecurityGroup"} } ]
}
},
"MesosMasterSecurityGroupIngress": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": { "Ref": "MesosMasterSecurityGroup" },
"IpProtocol": "-1",
"FromPort": "0",
"ToPort": "65535",
"SourceSecurityGroupId": { "Ref": "SecurityGroup" }
}
},
"WaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle"
}
}
}