-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathk8-kind-install.sh
272 lines (202 loc) · 6.31 KB
/
k8-kind-install.sh
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
#!/bin/bash
# check the OS
if [ -f /etc/redhat-release ]; then
# code for CentOS
echo "Running on CentOS"
cat << EOF > k8.sh
#!/bin/bash
echo "
#############################################################
# #
# This Script Install Kubernetes KIND on CentOS #
# #
#############################################################
"
# Check for hardware prerequisites
mem_size=\$(cat /proc/meminfo | grep MemTotal | awk '{print \$2}')
echo "Minimum memory required : 2097152 KB"
echo "Available memory : \$mem_size KB "
if [[ \$mem_size -lt 2097152 ]]; then
echo "Error: Your system does not meet the minimum memory requirement of 2GB " >&2
exit 1
fi
num_cpus=\$(nproc)
echo "Minimum CPU cores required : 2 cores"
echo "Available CPU cores : \$num_cpus cores"
if [[ \$num_cpus -lt 2 ]]; then
echo "Error: Your system does not meet the minimum CPU requirement of 2 cores " >&2
exit 1
fi
# Confirm with the user before proceeding
read -p "Do you want to proceed with the installation ? (y/n) " -n 1 -r
echo
if [[ ! \$REPLY =~ ^[Yy]\$ ]]
then
exit 1
fi
# Check for software prerequisites
if ! [ -x "\$(command -v curl)" ]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
if ! [ -x "\$(command -v yum)" ]; then
echo 'Error: yum is not installed.' >&2
exit 1
fi
# Get the hostname
echo "Enter the hostname:"
read hostname
hostnamectl set-hostname \$hostname
echo "`ip route get 1 | awk '{print \$NF;exit}'` \$hostname" >> /etc/hosts
# Update system
sudo yum update -y
# Install dependencies
sudo yum install -y conntrack socat
# Install necessary packages
yum install -y yum-utils device-mapper-persistent-data lvm2
#Install docker
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum -y update
sudo yum -y install docker-ce docker-ce-cli docker-compose-plugin --skip-broken
systemctl start docker
systemctl enable docker
# Remove containerd config file
yum install -y containerd.io
rm -f /etc/containerd/config.toml
# Restart containerd service
systemctl restart containerd
chkconfig --add containerd
# Add Kubernetes repository
printf "
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
" > /etc/yum.repos.d/kubernetes.repo
# Install Kubernetes components
yum install -y kubectl
# Enable and start kubelet service
systemctl enable --now kubelet
# Download and install Kind
curl -Lo kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64
chmod +x kind
sudo mv kind /usr/local/bin/
echo "export PATH=\$PATH:/usr/local/bin" >> ~/.bashrc
source ~/.bashrc
# Verify Kind installation
kind version
printf "
#2 nodes (1 worker & 1 master) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
" > config.yml
# Create a cluster
kind create cluster --config=config.yml
# Verify installation
kubectl cluster-info --context kind-kind
echo " Kind cluster created with 1 Master + 1 workers "
#nodes list
kubectl get nodes
EOF
chmod +x k8.sh
./k8.sh
elif [ -f /etc/lsb-release ]; then
# code for Ubuntu
echo "Running on Ubuntu"
cat << EOF > k8.sh
#!/bin/bash
echo "
#############################################################
# #
# This Script Install Kubernetes KIND on Ubuntu #
# #
#############################################################
"
# Check for hardware prerequisites
mem_size=\$(cat /proc/meminfo | grep MemTotal | awk '{print \$2}')
echo "Minimum memory required : 2097152 KB"
echo "Available memory : \$mem_size KB "
if [[ \$mem_size -lt 2097152 ]]; then
echo "Error: Your system does not meet the minimum memory requirement of 2GB " >&2
exit 1
fi
num_cpus=\$(nproc)
echo "Minimum CPU cores required : 2 cores"
echo "Available CPU cores : \$num_cpus cores"
if [[ \$num_cpus -lt 2 ]]; then
echo "Error: Your system does not meet the minimum CPU requirement of 2 cores " >&2
exit 1
fi
# Confirm with the user before proceeding
read -p "Do you want to proceed with the installation ? (y/n) " -n 1 -r
echo
if [[ ! \$REPLY =~ ^[Yy]\$ ]]
then
exit 1
fi
# Check for software prerequisites
if ! [ -x "\$(command -v curl)" ]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
if ! [ -x "\$(command -v apt-get)" ]; then
echo 'Error: apt-get is not installed.' >&2
exit 1
fi
# Get the hostname
echo "Enter the hostname:"
read hostname
hostnamectl set-hostname \$hostname
echo "`ip route get 1 | awk '{print \$NF;exit}'` \$hostname" >> /etc/hosts
# Install dependencies if not already installed
sudo apt-get update -y
apt-get -y -o upgrade
apt-get install -y apt-transport-https ca-certificates curl socat conntrack containerd software-properties-common docker-ce docker-ce-cli docker-compose-plugin
apt-get install -y docker.io
systemctl start docker
systemctl enable docker
rm -f /etc/containerd/config.toml
systemctl restart containerd
systemctl enable containerd
# Add Kubernetes apt repository
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
# Install kubectl
sudo apt-get update -y
sudo apt-get install -y kubectl kubelet
systemctl enable --now kubelet
curl -Lo kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64
chmod +x kind
sudo mv kind /usr/local/bin/
echo "export PATH=\\$PATH:/usr/local/bin" >> ~/.bashrc
source ~/.bashrc
printf "
#2 nodes (1 worker & 1 master) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
" > config.yml
# Create a cluster
kind create cluster --config=config.yml
# Verify installation
kubectl cluster-info --context kind-kind
echo " Kind cluster created with 1 Master + 1 worker "
#nodes list
kubectl get nodes
EOF
chmod +x k8.sh
./k8.sh
else
# code for other OS
echo "Not a supported OS"
exit
fi