-
Notifications
You must be signed in to change notification settings - Fork 31
/
mesos-slave.json
362 lines (338 loc) · 12.8 KB
/
mesos-slave.json
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Launches a pool of Mesos Slaves",
"Parameters" : {
"InstanceAmi" : {
"Description" : "Mesos AMI",
"Type" : "String"
},
"InstanceType" : {
"Description" : "EC2 instance type",
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [
"t2.micro", "t2.small", "t2.medium",
"m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge",
"c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
"c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
"r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge",
"i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge",
"hs1.8xlarge", "g2.2xlarge"
],
"ConstraintDescription" : "must be a valid, HVM-compatible EC2 instance type."
},
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "AWS::EC2::KeyPair::KeyName"
},
"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" : "AWS::EC2::SecurityGroup::Id"
},
"MesosMasterSecurityGroup" : {
"Description" : "Security group ID of Mesos Master nodes. If not passed, you'll need to grant network access on your own",
"Type" : "AWS::EC2::SecurityGroup::Id",
"Default" : ""
},
"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" : ""
},
"ConfigScriptS3Bucket" : {
"Description" : "(optional) S3 bucket of an executable to download and run after other boot-time provisioning (e.g., \"my-bucket\").",
"Type" : "String",
"Default" : ""
},
"ConfigScriptS3Path" : {
"Description" : "(optional) Path within ConfigScriptS3Bucket of an executable to download and run after other boot-time provisioning (e.g., \"/path/to/script\").",
"Type" : "String",
"Default" : ""
},
"MesosResources" : {
"Description" : "(optional) Resources to allocate to Mesos (as passed to --resources). To expose ports 8000-9000, for instance, you can use 'ports(*):[8000-9000, 31000-32000]'",
"Type" : "String",
"Default" : ""
},
"AdminSecurityGroup" : {
"Description" : "Existing security group that should be granted administrative access to Mesos (e.g., 'sg-123456')",
"Type" : "AWS::EC2::SecurityGroup::Id"
},
"Subnets" : {
"Description" : "List of VPC subnet IDs for the cluster. Must match the passed AvailabilityZones.",
"Type" : "List<AWS::EC2::Subnet::Id>"
},
"VpcId" : {
"Description" : "VPC associated with the provided subnets",
"Type" : "AWS::EC2::VPC::Id"
},
"AvailabilityZones": {
"Description" : "(Optional) If passed, only launch nodes in these AZs (e.g., 'us-east-1a,us-east-1b'). Must match the passed Subnets.",
"Type" : "CommaDelimitedList",
"Default" : ""
},
"StackCreationTimeout" : {
"Description" : "Timeout on initial stack creation",
"Type" : "String",
"Default": "PT10M"
}
},
"Conditions" : {
"EnableLogstashCondition" : { "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "LogstashConfig" }, ""] }] },
"EnableConfigScript" : { "Fn::And" : [
{ "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "ConfigScriptS3Bucket" }, ""] }]},
{ "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "ConfigScriptS3Path" }, ""] }]}
]},
"UseAllAvailabilityZones" : { "Fn::Equals" : [{ "Fn::Join" : ["", { "Ref" : "AvailabilityZones"} ]}, ""]},
"GrantNetworkAccess" : { "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "MesosMasterSecurityGroup"}, ""]}]}
},
"Resources" : {
"SlaveRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Principal": {
"Service": [ "ec2.amazonaws.com" ]
},
"Action": [ "sts:AssumeRole" ]
} ]
},
"Path": "/",
"Policies": [ {
"PolicyName": "root",
"PolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
{ "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ConfigScriptS3Bucket" }, { "Ref" : "ConfigScriptS3Path" }]]}
]
} ]
}
} ]
}
},
"SlaveInstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": [ {
"Ref": "SlaveRole"
} ]
}
},
"ServerGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : {
"Fn::If" : [
"UseAllAvailabilityZones",
{ "Fn::GetAZs": "AWS::Region" },
{"Ref" : "AvailabilityZones"}
]
},
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"MinSize" : { "Ref" : "ClusterSize" },
"MaxSize" : { "Ref" : "ClusterSize" },
"DesiredCapacity" : { "Ref" : "ClusterSize" },
"VPCZoneIdentifier" : { "Ref" : "Subnets" },
"Tags" : [
{
"Key" : "role",
"Value" : "mesos-slave",
"PropagateAtLaunch" : "true"
}
]
},
"CreationPolicy" : {
"ResourceSignal" : {
"Timeout" : { "Ref" : "StackCreationTimeout" }
}
}
},
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config": {
"packages" : {
"python": {
"awscli": []
}
},
"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://`/usr/local/bin/zk-list-nodes`/{{mesos_cluster_id}}\" > /etc/sv/mesos-slave/env/MESOS_MASTER",
"echo \"`/usr/bin/ec2metadata --public-hostname`\" > /etc/sv/mesos-slave/env/MESOS_HOSTNAME",
"echo \"{{executor_registration_timeout}}\" > /etc/sv/mesos-slave/env/MESOS_EXECUTOR_REGISTRATION_TIMEOUT",
"echo \"{{resources}}\" > /etc/sv/mesos-slave/env/MESOS_RESOURCES", ""
]]},
"context" : {
"mesos_cluster_id": { "Ref": "ClusterId" },
"executor_registration_timeout": "5mins",
"resources": { "Ref": "MesosResources" }
},
"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"
},
"/etc/default/docker": {
"content" : "DOCKER_OPTS=\"-g $(readlink -f /var/lib/docker)\"\n",
"mode" : "000644",
"owner" : "root",
"group" : "root"
}
}
}
}
},
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : { "Ref" : "InstanceAmi" },
"SecurityGroups" : [ { "Ref" : "SecurityGroup" }, { "Ref" : "ZkClientSecurityGroup" }, { "Ref" : "AdminSecurityGroup" } ],
"AssociatePublicIpAddress": "true",
"IamInstanceProfile" : { "Ref" : "SlaveInstanceProfile" },
"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\" ",
" --resource ServerGroup",
" --stack ", { "Ref" : "AWS::StackName" },
" --region ", { "Ref" : "AWS::Region" }, "\n",
" exit 1\n",
"}\n",
"# Process CloudFormation init definitions\n",
"cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r LaunchConfig ",
" --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",
"# Move docker dir to bigger device\n",
"service docker stop\n",
"mv /var/lib/docker /mnt/docker\n",
"ln -s /mnt/docker /var/lib/docker\n",
"service docker start\n",
"# Move Mesos workdir to bigger device\n",
"mkdir /mnt/mesos\n",
"ln -s /mnt/mesos /tmp/mesos\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",
{ "Fn::If" : [
"EnableConfigScript",
{ "Fn::Join" : ["", [
"# Download and run the user-provided config script \n",
"aws --region ", { "Ref" : "AWS::Region" },
" s3 cp s3://", { "Ref" : "ConfigScriptS3Bucket" }, { "Ref" : "ConfigScriptS3Path" }, " /tmp/cfn-user-config\n",
"chmod +x /tmp/cfn-user-config\n",
"/tmp/cfn-user-config || error_exit \n"
]]},
""
]},
"# All is well so signal success\n",
"cfn-signal -e 0 -r \"Stack setup complete\" ",
" --resource ServerGroup",
" --stack ", { "Ref" : "AWS::StackName" },
" --region ", { "Ref" : "AWS::Region" }, "\n",
"#EOF"
]]}}
}
},
"SecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Mesos Slaves",
"VpcId" : { "Ref" : "VpcId" }
}
},
"MasterToSlaveIngress" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Condition" : "GrantNetworkAccess",
"Properties" : {
"GroupId" : { "Ref" : "SecurityGroup" },
"IpProtocol" : "tcp",
"FromPort" : "5051",
"ToPort" : "5051",
"SourceSecurityGroupId" : { "Ref" : "MesosMasterSecurityGroup" }
}
},
"SlaveToMasterIngress" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Condition" : "GrantNetworkAccess",
"Properties" : {
"GroupId" : { "Ref" : "MesosMasterSecurityGroup" },
"IpProtocol" : "tcp",
"FromPort" : "5050",
"ToPort" : "5050",
"SourceSecurityGroupId" : { "Ref" : "SecurityGroup" }
}
}
}
}