-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux-one-node.yaml
146 lines (132 loc) · 4.33 KB
/
linux-one-node.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
AWSTemplateFormatVersion: '2010-09-09'
Description: Template to Create an EC2 instance in a VPC
Parameters:
ImageIDLinux:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::ImageIDLinux>'
Description: YOUR_IMAGE_ID
Default: ImageIDLinux
VpcId:
Type: String
Description: VPC id
Default: vpc-07377e6c
SubnetId:
Type: String
Description: Subnet in which to launch an EC2
Default: subnet-06377e6d
AvailabilityZone:
Type: String
Description: Availability Zone into which instance will launch
Default: us-west-2a
InstanceType:
Type: String
Description: Instance type
Default: i3.4xlarge
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Description: SSH Keypair to login to the instance
Default: mmalgeri777-keypair-mdb
MyIp:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::MyIp>'
Description: MY_IP
Default: MyIp
DemoIpRange:
Type: String
Description: Demo Ip Range
Default: 172.31.32.0/20
DemoIp1:
Type: String
Description: Demo Ip 1
Default: 172.31.42.77
primaryReplicaPassword:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::KeyPair::primaryReplicaPassword>'
Description: YOUR_PASSWORD
Default: primaryReplicaPassword
Resources:
linux1:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref ImageIDLinux
InstanceType: !Ref InstanceType
AvailabilityZone: !Ref AvailabilityZone
KeyName: !Ref KeyName
NetworkInterfaces:
- DeviceIndex: 0
PrivateIpAddress: !Ref DemoIp1
DeleteOnTermination: true
SubnetId: !Ref SubnetId
GroupSet:
- !Ref DemoSecurityGroup
- !Ref DemoHttpSecurityGroup
Tags:
- Key: Name
Value: linux1
UserData:
Fn::Base64: !Sub |
#!/bin/bash
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
echo "Installing mariadb enterprise"
yum update -y
echo "Updated yum"
echo "get private ip address"
ip=$(hostname -i)
echo "private address is "
echo $ip
sudo yum -y install wget
echo "Installed wget"
echo "Installing sshpass"
sudo yum -y install sshpass
echo "Stopping and disabling firewalld"
sudo systemctl stop firewalld
sudo systemctl disable firewalld
echo "firewalld stopped and disabled"
echo "Download and install kubectl"
sudo curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/bin/linux/amd64/kubectl
sudo chmod +x ./kubectl
sudo mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
sudo echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
echo "Download and install eksctl"
sudo 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
echo "Install http web server"
sudo yum install -y httpd # install web server
sudo systemctl start httpd
sudo systemctl enable httpd
sudo echo "Hello World" > /var/www/html/mainPage.html
DemoSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VpcId
GroupDescription: SG to allow SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref MyIp
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref DemoIpRange
- IpProtocol: tcp
FromPort: '3306'
ToPort: '3306'
CidrIp: !Ref DemoIpRange
Tags:
- Key: Name
Value: SSH-SG
DemoHttpSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VpcId
GroupDescription: SG to allow HTTP access via port 80
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: !Ref MyIp
Tags:
- Key: Name
Value: SSH-HTTPD
Outputs:
DemoInstanceId:
Description: Instance Id
Value: !Ref linux1