3131 echo " Containerd already installed, skipping..."
3232fi
3333
34- # Install containerd service file from the correct version
35- wget https://raw.githubusercontent.com/containerd/containerd/v${CONTAINERD_VERSION} /containerd.service
36- mkdir -p /usr/local/lib/systemd/system
37- mv containerd.service /usr/local/lib/systemd/system/containerd.service
38- systemctl daemon-reload
34+ SERVICE_FILE=" /usr/local/lib/systemd/system/containerd.service"
35+ if [ ! -f " $SERVICE_FILE " ]; then
36+ wget -q -O containerd.service " https://raw.githubusercontent.com/containerd/containerd/v${CONTAINERD_VERSION} /containerd.service"
37+ mkdir -p /usr/local/lib/systemd/system
38+ mv containerd.service " $SERVICE_FILE "
39+
40+ # Reload systemd only if a new file was added
41+ systemctl daemon-reload
42+ echo " Containerd service file updated and systemd reloaded."
43+ else
44+ echo " Containerd service file already exists. Skipping download."
45+ fi
3946
4047mkdir -p /etc/containerd
4148containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
@@ -44,10 +51,17 @@ sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.to
4451systemctl enable --now containerd
4552systemctl restart containerd
4653
47- # Install runc
48- wget https://github.com/opencontainers/runc/releases/download/v1.2.3/runc.amd64
49- install -m 755 runc.amd64 /usr/local/sbin/runc
50- rm -f runc.amd64
54+ RUNC_VERSION=" 1.2.3" # Set desired runc version
55+ RUNC_BIN=" /usr/local/sbin/runc"
56+ if [ -x " $RUNC_BIN " ] && [ " $( $RUNC_BIN --version | awk ' NR==1 {print $3}' ) " = " $RUNC_VERSION " ]; then
57+ echo " runc v$RUNC_VERSION is already installed. Skipping."
58+ else
59+ echo " Installing runc v$RUNC_VERSION ..."
60+ wget -q " https://github.com/opencontainers/runc/releases/download/v${RUNC_VERSION} /runc.amd64"
61+ install -m 755 runc.amd64 " $RUNC_BIN "
62+ rm -f runc.amd64
63+ echo " runc v$RUNC_VERSION installed successfully."
64+ fi
5165
5266echo " -------------Installing CNI Plugins-------------"
5367
@@ -57,20 +71,22 @@ CNI_TARBALL="cni-plugins-linux-amd64-v${CNI_VERSION}.tgz"
5771CNI_DIR=" /opt/cni/bin"
5872
5973mkdir -p ${CNI_DIR}
60- echo " Downloading CNI plugins..."
61- curl -O -L https://github.com/containernetworking/plugins/releases/download/v${CNI_VERSION} /${CNI_TARBALL}
62- tar Cxzvf ${CNI_DIR} ${CNI_TARBALL}
63- rm -f ${CNI_TARBALL}
64- echo " CNI plugins installed successfully!"
74+ if [ ! -f " ${CNI_DIR} /bridge" ]; then
75+ echo " Downloading CNI plugins..."
76+ curl -O -L https://github.com/containernetworking/plugins/releases/download/v${CNI_VERSION} /${CNI_TARBALL}
77+ tar Cxzvf ${CNI_DIR} ${CNI_TARBALL}
78+ rm -f ${CNI_TARBALL}
79+ echo " CNI plugins installed successfully!"
80+ else
81+ echo " CNI plugins already installed."
82+ fi
6583
6684modprobe br_netfilter
6785echo " br_netfilter" | sudo tee -a /etc/modules-load.d/modules.conf
6886echo " net.bridge.bridge-nf-call-iptables = 1" | sudo tee -a /etc/sysctl.conf
6987sudo sysctl -p
7088
71- # Create the directory with proper permissions (if not already exists)
7289sudo mkdir -p -m 755 /etc/apt/keyrings
73-
7490# Check if the key file already exists
7591if [ ! -f /etc/apt/keyrings/kubernetes-apt-keyring.gpg ]; then
7692 # Download the key if it doesn't exist
0 commit comments