-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.yaml
155 lines (149 loc) · 4.65 KB
/
template.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
AWSTemplateFormatVersion: "2010-09-09"
Description: Deploy Kuberentes Cluster with 1 Master Node and 1 Worker Node
Parameters:
InstanceType:
Description: Enter t2.micro, t3.medium, or t3.large. Default is t3.medium.
Type: String
Default: t3.medium
AllowedValues:
- t2.micro
- t3.medium
- t3.large
ImageAMIId:
Description: Enter a valid ami image ID
Type: String
VolumeSizeEC2:
Description: Enter the desired Volume Size
Type: Number
Default: 20
Resources:
MasterNodeKubernetesSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SecurityGroup for Kubernetes Cluster - Master Node
GroupName: KuberentesSGMasterNode
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: "SSH to EC2 Instances"
FromPort: 22
IpProtocol: tcp
ToPort: 22
- CidrIp: 0.0.0.0/0
Description: "Kubernetes API server"
FromPort: 6443
IpProtocol: tcp
ToPort: 6443
- CidrIp: 0.0.0.0/0
Description: "etcd server client API"
FromPort: 2379
IpProtocol: tcp
ToPort: 2380
- CidrIp: 0.0.0.0/0
Description: "kubelet API"
FromPort: 10250
IpProtocol: tcp
ToPort: 10250
- CidrIp: 0.0.0.0/0
Description: "kube-scheduler"
FromPort: 10251
IpProtocol: tcp
ToPort: 10251
- CidrIp: 0.0.0.0/0
Description: "kube-controller-manager"
FromPort: 10252
IpProtocol: tcp
ToPort: 10252
Tags:
- Key: Name
Value: Kuberentes SG Master Node
WorkerNodeKubernetesSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SecurityGroup for Kubernetes Cluster - Worker Node
GroupName: KuberentesSGWorkerNode
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: "SSH to EC2 Instances"
FromPort: 22
IpProtocol: tcp
ToPort: 22
- CidrIp: 0.0.0.0/0
Description: "kubelet API"
FromPort: 10250
IpProtocol: tcp
ToPort: 10250
- CidrIp: 0.0.0.0/0
Description: "NodePort Services"
FromPort: 30000
IpProtocol: tcp
ToPort: 32767
Tags:
- Key: Name
Value: Kuberentes SG Worker Node
WorkerNode:
DependsOn: WorkerNodeKubernetesSG
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageAMIId
InstanceInitiatedShutdownBehavior: terminate
InstanceType: !Ref InstanceType
KeyName: pc-ssh
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
cd /home/ubuntu
echo pwd
su ubuntu -c "git clone https://github.com/Naz513/kubernetes-ubuntu.git"
cd kubernetes-ubuntu/
su ubuntu -c "chmod +x install_components.sh"
SecurityGroupIds:
- !Ref WorkerNodeKubernetesSG
Tags:
- Key: Name
Value: WrokerNode
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: !Ref VolumeSizeEC2
VolumeType: gp2
DeleteOnTermination: true
MasterNode:
DependsOn: MasterNodeKubernetesSG
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageAMIId
InstanceInitiatedShutdownBehavior: terminate
InstanceType: !Ref InstanceType
KeyName: pc-ssh
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
cd /home/ubuntu
echo pwd
su ubuntu -c "git clone https://github.com/Naz513/kubernetes-ubuntu.git"
cd kubernetes-ubuntu/
su ubuntu -c "chmod +x install_components.sh kube_init.sh kubernetes_dashboard.sh"
SecurityGroupIds:
- !Ref MasterNodeKubernetesSG
Tags:
- Key: Name
Value: MasterNode
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: !Ref VolumeSizeEC2
VolumeType: gp2
DeleteOnTermination: true
Outputs:
MasterNodeIP:
Description: IP of Master Node
Value: !GetAtt MasterNode.PublicIp
MasterNodeConnectSSH:
Description: SSH into Master Node
Value: !Sub ssh -i "pc-ssh.pem" ubuntu@${MasterNode.PublicDnsName}
WorkerNodeIP:
Description: IP of Worker Node
Value: !GetAtt WorkerNode.PublicIp
WorkerNodeConnectSSH:
Description: SSH into Worker Node
Value: !Sub ssh -i "pc-ssh.pem" ubuntu@${WorkerNode.PublicDnsName}