-
Notifications
You must be signed in to change notification settings - Fork 10
/
k8-minikube.sh
255 lines (186 loc) · 6.44 KB
/
k8-minikube.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
#!/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 MINIKUBE 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
# Install dependencies
sudo yum install -y conntrack
# 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 the kubeadm repo
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 minikube
sudo yum install -y kubectl kubelet kubeadm
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube
sudo mv minikube /usr/local/bin/
echo "export PATH=\$PATH:/usr/local/bin" >> ~/.bashrc
source ~/.bashrc
# Configure kubelet to use containerd as the CRI
sudo sh -c "echo 'KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock' >> /etc/sysconfig/kubelet"
# Restart kubelet service
sudo systemctl restart kubelet
# Start minikube with containerd as the runtime
minikube start --driver=docker --force
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 MINIKUBE 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
sudo apt-get install -y conntrack
# Update the apt package list and install necessary packages
sudo apt-get update -y
sudo apt-get -o upgrade -y
sudo apt-get install -y yum-utils device-mapper-persistent-data lvm2
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
systemctl start docker
systemctl enable docker
# Remove containerd config file
rm -f /etc/containerd/config.toml
# Restart containerd service
systemctl restart containerd
systemctl enable containerd
# Add the kubeadm repo
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
sudo apt-get update -y
# Install kubectl, kubelet, and kubeadm
sudo apt-get install -y kubectl kubelet kubeadm
# Download minikube binary
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
# Make the binary executable
chmod +x minikube
# Move the binary to a directory in PATH
sudo mv minikube /usr/local/bin/
# Add the directory to PATH in .bashrc
echo "export PATH=\$PATH:/usr/local/bin" >> ~/.bashrc
# Reload .bashrc
source ~/.bashrc
# Configure kubelet to use containerd as the CRI
sudo sh -c "echo 'KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock' >> /etc/sysconfig/kubelet"
# Restart kubelet service
sudo systemctl restart kubelet
# Start minikube with containerd as the runtime
minikube start --driver=docker --force
EOF
chmod +x k8.sh
./k8.sh
else
# code for other OS
echo "Not a supported OS"
exit
fi