forked from marceldegraaf/blog-coreos-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.yml
241 lines (214 loc) · 5.81 KB
/
stack.yml
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
AWSTemplateFormatVersion: 2010-09-09
Description: CoreOS stack
# Mappings
# =================================================
Mappings:
RegionMap:
eu-west-1:
ami: ami-8368adf4
us-east-1:
ami: ami-3becf652
us-west-1:
ami: ami-e4dde5a1
us-west-2:
ami: ami-388bfe08
ap-southeast-1:
ami: ami-28bdee7a
ap-southeast-2:
ami: ami-7d2fb747
ap-northeast-1:
ami: ami-fb5822fa
sa-east-1:
ami: ami-83c76a9e
# Parameters
# =================================================
Parameters:
InstanceType:
Description: "EC2 instance type (e.g. m1.small, c1.medium, ...)"
Type: String
Default: c3.large
AllowedValues: [ t1.micro, m1.small, m1.medium, m1.large, m1.xlarge, m3.xlarge, m3.2xlarge, m2.xlarge, m2.2xlarge, m2.4xlarge, c1.medium, c1.xlarge, cc1.4xlarge, cc2.8xlarge, cg1.4xlarge, hi1.4xlarge, hs1.8xlarge, c3.large, c3.xlarge ]
ConstraintDescription: Must be a valid EC2 instance type
ClusterSize:
Description: Number of nodes in your cluster (3-12)
Type: Number
Default: 2
MinValue: 2
MaxValue: 12
DiscoveryURL:
Description: An unique etcd cluster discovery URL. Grab a new token from https://discovery.etcd.io/new
Type: String
AdvertisedIPAddress:
Type: String
Description: "Use 'private' if your etcd cluster is within one region or 'public' if it spans regions or cloud providers."
Default: private
AllowedValues: [ private, public ]
AllowSSHFrom:
Description: The net block (CIDR) that SSH is available to.
Default: "0.0.0.0/0"
Type: String
KeyPair:
Description: The name of an existing EC2 Key Pair to allow SSH access to the instance.
Type: String
# Resources
# =================================================
Resources:
CoreOSELB:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
CrossZone: true
Listeners:
- InstancePort: 80
Protocol: HTTP
LoadBalancerPort: 80
HealthCheck:
HealthyThreshold: 2
Timeout: 9
Interval: 10
UnhealthyThreshold: 5
Target: "HTTP:80/"
AvailabilityZones:
"Fn::GetAZs":
Ref: "AWS::Region"
CoreOSAccessKey:
Type: AWS::IAM::AccessKey
Properties:
UserName:
Ref: CoreOSUser
CoreOSUser:
DependsOn: CoreOSELB
Type: AWS::IAM::User
Properties:
Policies:
- PolicyName: ebs
PolicyDocument:
Statement:
- Effect: Allow
Action: "elb:*"
Resource: "*"
CoreOSSecurityGroup:
DependsOn: CoreOSELB
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: CoreOS SecurityGroup
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp:
Ref: AllowSSHFrom
- FromPort: 80
ToPort: 80
IpProtocol: tcp
SourceSecurityGroupOwnerId:
"Fn::GetAtt":
- CoreOSELB
- "SourceSecurityGroup.OwnerAlias"
SourceSecurityGroupName:
"Fn::GetAtt":
- CoreOSELB
- "SourceSecurityGroup.GroupName"
Ingress4001:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupName:
Ref: CoreOSSecurityGroup
IpProtocol: tcp
FromPort: 4001
ToPort: 4001
SourceSecurityGroupId:
"Fn::GetAtt":
- CoreOSSecurityGroup
- GroupId
Ingress7001:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupName:
Ref: CoreOSSecurityGroup
IpProtocol: tcp
FromPort: 7001
ToPort: 7001
SourceSecurityGroupId:
"Fn::GetAtt":
- CoreOSSecurityGroup
- GroupId
IngressApps:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupName:
Ref: CoreOSSecurityGroup
IpProtocol: tcp
FromPort: 5000
ToPort: 6000
SourceSecurityGroupId:
"Fn::GetAtt":
- CoreOSSecurityGroup
- GroupId
CoreOSServerAutoScale:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones:
"Fn::GetAZs":
Ref: "AWS::Region"
LaunchConfigurationName:
Ref: CoreOSServerLaunchConfig
MinSize: 2
MaxSize: 12
DesiredCapacity:
Ref: ClusterSize
LoadBalancerNames:
- Ref: CoreOSELB
Tags:
- Key: Name
Value:
Ref: "AWS::StackName"
PropagateAtLaunch: true
CoreOSServerLaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId:
"Fn::FindInMap":
- RegionMap
- Ref: AWS::Region
- ami
InstanceType:
Ref: InstanceType
KeyName:
Ref: KeyPair
SecurityGroups:
- Ref: CoreOSSecurityGroup
UserData:
"Fn::Base64":
"Fn::Join":
- ""
-
- "#cloud-config\n\n"
- "coreos:\n"
- " etcd:\n"
- " discovery: "
- Ref: DiscoveryURL
- "\n"
- " addr: $"
- Ref: AdvertisedIPAddress
- "_ipv4:4001\n"
- " peer-addr: $"
- Ref: AdvertisedIPAddress
- "_ipv4:7001\n"
- " units:\n"
- " - name: etcd.service\n"
- " command: start\n"
- " - name: fleet.service\n"
- " command: start\n"
# Outputs
# =================================================
Outputs:
AccessKeyId:
Description: AWS AccessKeyId for the coreos IAM user
Value:
Ref: CoreOSAccessKey
SecretAccessKey:
Description: AWS SecretAccessKey for the coreos IAM user
Value:
"Fn::GetAtt":
- CoreOSAccessKey
- SecretAccessKey