-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.sh
120 lines (89 loc) · 3.24 KB
/
worker.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
#!/bin/bash
echo "Disable Selinux"
setenforce 0
echo "Download required kernel packages"
sudo dnf install kernel-devel-$(uname -r) -y
echo "Adding Kernel modules"
sudo modprobe br_netfilter
sudo modprobe ip_vs
sudo modprobe ip_vs_rr
sudo modprobe ip_vs_wrr
sudo modprobe ip_vs_sh
sudo modprobe overlay
echo "Next, create a configuration file (as the root user on each node) to ensure these modules load at system boot"
cat > /etc/modules-load.d/kubernetes.conf << EOF
br_netfilter
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
overlay
EOF
echo "set specific sysctl settings (on each node) that Kubernetes relies on"
cat > /etc/sysctl.d/kubernetes.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
echo "Applying sysctl changes"
sysctl --system
echo "Disabling Swap"
sudo swapoff -a
sed -e '/swap/s/^/#/g' -i /etc/fstab
echo "Add the Docker CE Repository"
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
echo "Update Package Cache"
sudo dnf makecache
echo "install the containerd.io package"
sudo dnf -y install containerd.io
echo "Building default container configuration"
sudo sh -c "containerd config default > /etc/containerd/config.toml"
#vim /etc/containerd/config.toml
CONFIG_FILE="/etc/containerd/config.toml"
# Check if SystemdCgroup is set to false
if grep -q "SystemdCgroup = false" "$CONFIG_FILE"; then
echo "SystemdCgroup is set to false. Changing it to true..."
# Change SystemdCgroup to true
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' "$CONFIG_FILE"
echo "SystemdCgroup has been updated to true."
else
echo "SystemdCgroup is already set to true or not set at all. No changes made."
fi
# Verify the change
echo "Verifying the change..."
grep "SystemdCgroup = true" "$CONFIG_FILE"
if [ $? -eq 0 ]; then
echo "SystemdCgroup is correctly set to true."
else
echo "Failed to update SystemdCgroup."
fi
echo "Start the container service at boot"
sudo systemctl enable --now containerd.service
systemctl unmask firewalld
systemctl enable firewalld
systemctl start firewalld
sudo firewall-cmd --zone=public --permanent --add-port=6443/tcp
sudo firewall-cmd --zone=public --permanent --add-port=2379-2380/tcp
sudo firewall-cmd --zone=public --permanent --add-port=10250/tcp
sudo firewall-cmd --zone=public --permanent --add-port=10251/tcp
sudo firewall-cmd --zone=public --permanent --add-port=10252/tcp
sudo firewall-cmd --zone=public --permanent --add-port=10255/tcp
sudo firewall-cmd --zone=public --permanent --add-port=5473/tcp
sudo firewall-cmd --reload
echo "Add Kubernetes Repository"
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
EOF
echo "Install Kubernetes Packages"
dnf makecache
dnf install -y kubelet kubeadm kubectl --disableexcludes=Kubernetes
echo "Start and Enable kubelet Service"
systemctl enable --now kubelet.service
sudo hostnamectl set-hostname worker-node
sudo kubeadm reset -y
sudo rm -rf /etc/kubernetes/pki