-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheksctl_on_ec2.yaml
661 lines (640 loc) · 21.4 KB
/
eksctl_on_ec2.yaml
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
AWSTemplateFormatVersion: "2010-09-09"
Description: "CloudFormation Template"
Mappings:
# https://aws.amazon.com/ko/blogs/korea/limit-access-to-your-origins-using-the-aws-managed-prefix-list-for-amazon-cloudfront
# aws ec2 describe-managed-prefix-lists --region <REGION> | jq -r '.PrefixLists[] | select (.PrefixListName == "com.amazonaws.global.cloudfront.origin-facing") | .PrefixListId'
AWSRegions2PrefixListID:
ap-northeast-1:
PrefixList: pl-58a04531
ap-northeast-2:
PrefixList: pl-22a6434b
ap-northeast-3:
PrefixList: pl-31a14458
ap-south-1:
PrefixList: pl-9aa247f3
ap-southeast-1:
PrefixList: pl-31a34658
ap-southeast-2:
PrefixList: pl-b8a742d1
ca-central-1:
PrefixList: pl-38a64351
eu-central-1:
PrefixList: pl-a3a144ca
eu-north-1:
PrefixList: pl-fab65393
eu-west-1:
PrefixList: pl-4fa04526
eu-west-2:
PrefixList: pl-93a247fa
eu-west-3:
PrefixList: pl-75b1541c
sa-east-1:
PrefixList: pl-5da64334
us-east-1:
PrefixList: pl-3b927c52
us-east-2:
PrefixList: pl-b6a144df
us-west-1:
PrefixList: pl-4ea04527
us-west-2:
PrefixList: pl-82a045eb
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: EKS Cluster
Parameters:
- EksClusterName
- EksClusterVersion
- Label:
default: EKS Managed Node Group (MNG)
Parameters:
- EksMngAmiFamily
- EksMngInstanceType
- EksMngDesiredCapacity
- Label:
default: Network
Parameters:
- Prefix
- VpcCidrBlock
- EnableDnsHostnamesOption
- EnableDnsResolutionOption
- Label:
default: VsCodeOnEc2
Parameters:
- AmiId
- InstanceType
- SsmRunCommandShellScript
Parameters:
EksClusterName:
Type: String
Default: eks-cluster
AllowedPattern: ".+"
ConstraintDescription: "Parameter [EksClusterName] is invalid"
EksClusterVersion:
Type: String
Default: 1.31
AllowedValues:
# - 1.32
- 1.31
- 1.30
- 1.29
- 1.28
- 1.27
- 1.26
- 1.25
ConstraintDescription: "Parameter [EksClusterVersion] is invalid"
EksMngAmiFamily:
Type: String
Default: AmazonLinux2023
AllowedValues:
- AmazonLinux2023
- AmazonLinux2
- UbuntuPro2204
- Ubuntu2204
- Ubuntu2004
- Ubuntu1804
- Bottlerocket
- WindowsServer2022CoreContainer
- WindowsServer2022FullContainer
- WindowsServer2019CoreContainer
- WindowsServer2019FullContainer
ConstraintDescription: "Parameter [EksMngAmiFamily] is invalid"
EksMngInstanceType:
Type: String
Default: t3.xlarge
AllowedValues:
- t1.micro
- t2.2xlarge
- t2.large
- t2.medium
- t2.micro
- t2.nano
- t2.small
- t2.xlarge
- t3.2xlarge
- t3.large
- t3.medium
- t3.micro
- t3.nano
- t3.small
- t3.xlarge
- t3a.2xlarge
- t3a.large
- t3a.medium
- t3a.micro
- t3a.nano
- t3a.small
- t3a.xlarge
- t4g.2xlarge
- t4g.large
- t4g.medium
- t4g.micro
- t4g.nano
- t4g.small
- t4g.xlarge
ConstraintDescription: "Parameter [EksMngInstanceType] is invalid"
EksMngDesiredCapacity:
Type: Number
Default: 2
MinValue: 0
MaxValue: 6
ConstraintDescription: "Parameter [EksMngDesiredCapacity] is invalid"
Prefix:
Description: Name Tag Auto-generation ("project" -> project-vpc, project-igw, ...)
Type: String
Default: eks
AllowedPattern: ".+"
ConstraintDescription: "Parameter [Prefix] must not be empty"
VpcCidrBlock:
Description: CIDR Block for the VPC to Create (ex 10.0.0.0/16)
Type: String
Default: 10.0.0.0/16
AllowedPattern: '(([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([1-2][0-9]|3[0-1])'
ConstraintDescription: "Parameter [VpcCidrBlock] is invalid"
EnableDnsHostnamesOption:
Type: String
Default: true
AllowedValues:
- true
- false
EnableDnsResolutionOption:
Type: String
Default: true
AllowedValues:
- true
- false
AmiId:
Description: EC2 AMI Id
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64
AllowedValues:
# aws ssm get-parameters-by-path --path /aws/service/ami-amazon-linux-latest --query 'Parameters[].Name'
- /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-arm64
- /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64
- /aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-6.1-arm64
- /aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-6.1-x86_64
- /aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-default-arm64
- /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2
- /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3
- /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs
- /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
- /aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-x86_64-ebs
- /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64
- /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64
- /aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-default-x86_64
- /aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-ebs
- /aws/service/ami-amazon-linux-latest/amzn-ami-minimal-hvm-x86_64-ebs
- /aws/service/ami-amazon-linux-latest/amzn-ami-minimal-hvm-x86_64-s3
- /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-arm64-gp2
- /aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-arm64-gp2
- /aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-x86_64-gp2
- /aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-arm64-ebs
- /aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-x86_64-ebs
InstanceType:
Description: EC2 Instance Type
Type: String
Default: t3.medium
AllowedValues:
- t1.micro
- t2.2xlarge
- t2.large
- t2.medium
- t2.micro
- t2.nano
- t2.small
- t2.xlarge
- t3.2xlarge
- t3.large
- t3.medium
- t3.micro
- t3.nano
- t3.small
- t3.xlarge
- t3a.2xlarge
- t3a.large
- t3a.medium
- t3a.micro
- t3a.nano
- t3a.small
- t3a.xlarge
- t4g.2xlarge
- t4g.large
- t4g.medium
- t4g.micro
- t4g.nano
- t4g.small
- t4g.xlarge
Resources:
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCidrBlock
EnableDnsSupport: !Ref EnableDnsResolutionOption
EnableDnsHostnames: !Ref EnableDnsHostnamesOption # for EC2 PublicDnsName, ...
Tags:
- Key: Name
Value: !Ref Prefix
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub "${Prefix}-igw"
VpcInternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref Vpc
PublicSubnetRouteTable:
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key: Name
Value: !Sub "${Prefix}-rtb-public"
VpcId: !Ref Vpc
PublicSubnetRoute:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
RouteTableId: !Ref PublicSubnetRouteTable
# Public Subnet 1 (AZ a)
PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Sub ${AWS::Region}a
CidrBlock: !Select [0, !Cidr [!GetAtt Vpc.CidrBlock, 6, 8]]
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub "${Prefix}-subnet-public1-${AWS::Region}a"
- Key: kubernetes.io/role/elb
Value: 1
VpcId: !Ref Vpc
PublicSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicSubnetRouteTable
SubnetId: !Ref PublicSubnet1
# Public Subnet 2 (AZ b)
PublicSubnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Sub ${AWS::Region}b
CidrBlock: !Select [1, !Cidr [!GetAtt Vpc.CidrBlock, 6, 8]]
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub "${Prefix}-subnet-public2-${AWS::Region}b"
- Key: kubernetes.io/role/elb
Value: 1
VpcId: !Ref Vpc
PublicSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicSubnetRouteTable
SubnetId: !Ref PublicSubnet2
# Private Subnet 1 (AZ a)
PrivateSubnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Sub ${AWS::Region}a
CidrBlock: !Select [3, !Cidr [!GetAtt Vpc.CidrBlock, 6, 8]]
Tags:
- Key: Name
Value: !Sub "${Prefix}-subnet-private1-${AWS::Region}a"
- Key: kubernetes.io/role/internal-elb
Value: 1
VpcId: !Ref Vpc
NatGateway1ElasticIp:
Type: AWS::EC2::EIP
NatGateway1:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGateway1ElasticIp.AllocationId
SubnetId: !Ref PublicSubnet1
Tags:
- Key : Name
Value : !Sub "${Prefix}-nat-public1-${AWS::Region}a"
PrivateSubnet1RouteTable:
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key : Name
Value : !Sub "${Prefix}-rtb-private1-${AWS::Region}a"
VpcId: !Ref Vpc
PrivateSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateSubnet1RouteTable
SubnetId: !Ref PrivateSubnet1
PrivateSubnet1Route:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway1
RouteTableId: !Ref PrivateSubnet1RouteTable
# Private Subnet 2 (AZ b)
PrivateSubnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Sub ${AWS::Region}b
CidrBlock: !Select [4, !Cidr [!GetAtt Vpc.CidrBlock, 6, 8]]
Tags:
- Key: Name
Value: !Sub "${Prefix}-subnet-private2-${AWS::Region}b"
- Key: kubernetes.io/role/internal-elb
Value: 1
VpcId: !Ref Vpc
NatGateway2ElasticIp:
Type: AWS::EC2::EIP
NatGateway2:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGateway2ElasticIp.AllocationId
SubnetId: !Ref PublicSubnet2
Tags:
- Key : Name
Value : !Sub "${Prefix}-nat-public2-${AWS::Region}b"
PrivateSubnet2RouteTable:
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key : Name
Value : !Sub "${Prefix}-rtb-private2-${AWS::Region}b"
VpcId: !Ref Vpc
PrivateSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateSubnet2RouteTable
SubnetId: !Ref PrivateSubnet2
PrivateSubnet2Route:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway2
RouteTableId: !Ref PrivateSubnet2RouteTable
KeyPair:
Type: AWS::EC2::KeyPair
Properties:
KeyName: !Join
- '-'
- - key
- !Select [4, !Split ['-', !Select [2, !Split ['/', !Ref AWS::StackId]]]]
VsCodeOnEc2:
Type: AWS::EC2::Instance
CreationPolicy:
ResourceSignal:
Count: '1'
Timeout: PT10M
Properties:
ImageId: !Ref AmiId
InstanceType: !Ref InstanceType
KeyName: !Ref KeyPair
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeviceIndex: 0
SubnetId: !Ref PublicSubnet1
GroupSet:
- !Ref VsCodeOnEc2SecurityGroup
Tags:
- Key: Name
Value: vscode
IamInstanceProfile: !Ref VsCodeOnEc2InstanceProfile
UserData:
# https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/install-kubectl.html#_step_2_install_or_update_kubectl
!Base64
Fn::Sub: |
#!/bin/bash
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource VsCodeOnEc2 --region ${AWS::Region}
dnf update -y
dnf install -y -q git
dnf groupinstall -y -q "Development Tools"
dnf install -y -q python3.12
python3.12 -m ensurepip --upgrade
python3.12 -m pip install --upgrade pip
ln -sf /usr/bin/python3.12 /usr/bin/python
echo "alias pip=pip3" >> ~/.bashrc
export CODE_SERVER_VERSION="4.96.4"
wget -q https://github.com/coder/code-server/releases/download/v$CODE_SERVER_VERSION/code-server-$CODE_SERVER_VERSION-linux-amd64.tar.gz
tar -xzf code-server-$CODE_SERVER_VERSION-linux-amd64.tar.gz
mv code-server-$CODE_SERVER_VERSION-linux-amd64 /usr/local/lib/code-server
ln -s /usr/local/lib/code-server/bin/code-server /usr/local/bin/code-server
mkdir -p /home/ec2-user/.config/code-server
cat <<EOF > /home/ec2-user/.config/code-server/config.yaml
bind-addr: 0.0.0.0:8000
auth: none
cert: false
EOF
chown -R ec2-user:ec2-user /home/ec2-user/.config
cat <<EOF > /etc/systemd/system/code-server.service
[Unit]
Description=VS Code Server
After=network.target
[Service]
Type=simple
User=ec2-user
ExecStart=/usr/local/bin/code-server --config /home/ec2-user/.config/code-server/config.yaml /home/ec2-user
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now code-server
dnf install -y -q docker
systemctl enable --now docker
# usermod -aG docker ec2-user
# newgrp docker
# VS Code Server Terminal(Bash) Deletes "docker" group...
chmod 666 /var/run/docker.sock
VsCodeOnEc2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for VS Code EC2 SSH Connection
GroupName: !Join
- '-'
- - vscode-ec2-sg
- !Select [4, !Split ['-', !Select [2, !Split ['/', !Ref AWS::StackId]]]]
VpcId: !Ref Vpc
SecurityGroupIngress:
- Description: com.amazonaws.global.cloudfront.origin-facing
IpProtocol: tcp
FromPort: 8000
ToPort: 8000
SourcePrefixListId: !FindInMap
- AWSRegions2PrefixListID
- !Ref AWS::Region
- PrefixList
VsCodeOnEc2IamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess
VsCodeOnEc2InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref VsCodeOnEc2IamRole
# https://docs.aws.amazon.com/ko_kr/AmazonCloudFront/latest/DeveloperGuide/distribution-working-with.websockets.html
# https://github.com/aws-samples/code-server-setup-with-cloudformation/blob/main/code-server-stack.yaml
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: !GetAtt VsCodeOnEc2.PublicDnsName
Id: !GetAtt VsCodeOnEc2.PublicDnsName
CustomOriginConfig:
HTTPPort: 8000
OriginProtocolPolicy: http-only
Enabled: true
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
- PUT
- POST
- PATCH
- DELETE
ForwardedValues:
QueryString: 'false'
Compress: false
TargetOriginId: !GetAtt VsCodeOnEc2.PublicDnsName
ViewerProtocolPolicy: allow-all
CachePolicyId: !Ref CloudFrontCachePolicy
OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3 # AllViewer
CloudFrontCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 1
Name: !Join
- '-'
- - VSCode
- !Select
- 4
- !Split
- '-'
- !Select
- 2
- !Split
- /
- !Ref AWS::StackId
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: all
EnableAcceptEncodingGzip: false
HeadersConfig:
HeaderBehavior: whitelist
Headers:
- Accept-Charset
- Authorization
- Origin
- Accept
- Referer
- Host
- Accept-Language
- Accept-Encoding
- Accept-Datetime
QueryStringsConfig:
QueryStringBehavior: all
SsmAssociation:
Type: AWS::SSM::Association
Properties:
Name: AWS-RunShellScript
WaitForSuccessTimeoutSeconds: 900
Targets:
- Key: InstanceIds
Values:
- !Ref VsCodeOnEc2
Parameters:
commands:
# uid=0(root) gid=0(root) groups=0(root) context=system_u:system_r:unconfined_service_t:s0
- !Sub |
su - ec2-user << EOF
mkdir -p /home/ec2-user/bin
curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.31.2/2024-11-15/bin/linux/amd64/kubectl
chmod +x kubectl
mv kubectl /home/ec2-user/bin/kubectl
export PATH=/home/ec2-user/bin:$PATH
echo "export PATH=/home/ec2-user/bin:$PATH" >> ~/.bashrc
echo "alias k=kubectl" >> ~/.bashrc
echo "complete -o default -F __start_kubectl k" >> ~/.bashrc
echo "source <(kubectl completion bash)" >> ~/.bashrc
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
aws configure set default.region ${AWS::Region}
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > /home/ec2-user/get_helm.sh
chmod 700 /home/ec2-user/get_helm.sh
/home/ec2-user/get_helm.sh
mkdir -p /home/ec2-user/eksctl
# echo '#!/bin/bash
# cluster_name="${EksClusterName}"
# bastion_id=\$(ec2-metadata -i | cut -d " " -f 2)
# cluster_sg=\$(aws eks describe-cluster --name \$cluster_name --query "cluster.resourcesVpcConfig.clusterSecurityGroupId" --output text)
# bastion_sg=\$(aws ec2 describe-instances --instance-ids \$bastion_id --query "Reservations[].Instances[].SecurityGroups[].GroupId" --output text)
# aws ec2 modify-instance-attribute --instance-id \$bastion_id --groups \$bastion_sg \$cluster_sg' > /home/ec2-user/eksctl/security_group.sh
echo '# eksctl create cluster -f /home/ec2-user/eksctl/cluster.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: ${EksClusterName}
region: ${AWS::Region}
version: "${EksClusterVersion}"
vpc:
id: ${Vpc}
subnets:
public:
public1:
id: ${PublicSubnet1}
public2:
id: ${PublicSubnet2}
private:
private1:
id: ${PrivateSubnet1}
private2:
id: ${PrivateSubnet2}
managedNodeGroups:
- name: nodegroup
amiFamily: ${EksMngAmiFamily}
instanceType: ${EksMngInstanceType}
desiredCapacity: ${EksMngDesiredCapacity}
privateNetworking: true
iam:
attachPolicyARNs:
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
addons:
- name: coredns
resolveConflicts: overwrite
- name: kube-proxy
resolveConflicts: overwrite
- name: vpc-cni
resolveConflicts: overwrite
- name: eks-pod-identity-agent
resolveConflicts: overwrite
- name: metrics-server
resolveConflicts: overwrite
iam:
withOIDC: true # eksctl utils associate-iam-oidc-provider --cluster ${EksClusterName} --approve' > /home/ec2-user/eksctl/cluster.yaml
EOF
Outputs:
CloudFrontDomainName:
Value: !Sub
- https://${domain}
- domain: !GetAtt CloudFrontDistribution.DomainName