11#! /bin/bash
22set -euo pipefail
3+
34DEFAULT_CONTAINERD_VERSION=1.7.24
45DEFAULT_CNI_PLUGIN_VERSIONS=1.6.2
56CONTAINERD_VERSION=" ${CONTAINERD_VERSION:= $DEFAULT_CONTAINERD_VERSION } "
67CNI_PLUGIN_VERSIONS=" ${CNI_PLUGIN_VERSIONS:= $DEFAULT_CNI_PLUGIN_VERSIONS } "
8+ PATCH_VERSION=${1# [v]}
9+ VERSION=${PATCH_VERSION% .* }
710
811# setup containerd config
9- mkdir -p -m 755 /etc/containerd
12+ # shellcheck disable=SC2174
13+ if ! mkdir -p -m 755 /etc/containerd ; then
14+ echo " Error: Failed to create directory /etc/containerd" >&2
15+ exit 1
16+ fi
17+
1018cat > /etc/containerd/config.toml << EOF
1119version = 2
1220imports = ["/etc/containerd/conf.d/*.toml"]
2533
2634chmod 644 /etc/containerd/config.toml
2735
28- mkdir -p -m 755 /etc/modules-load.d
36+ # shellcheck disable=SC2174
37+ if ! mkdir -p -m 755 /etc/modules-load.d ; then
38+ echo " Error: Failed to create directory /etc/modules-load.d" >&2
39+ exit 1
40+ fi
41+
2942cat > /etc/modules-load.d/k8s.conf << EOF
3043overlay
3144br_netfilter
3245EOF
3346
3447chmod 644 /etc/modules-load.d/k8s.conf
3548
36- mkdir -p -m 755 /etc/sysctl.d
49+ # shellcheck disable=SC2174
50+ if ! mkdir -p -m 755 /etc/sysctl.d ; then
51+ echo " Error: Failed to create directory /etc/sysctl.d" >&2
52+ exit 1
53+ fi
54+
3755cat > /etc/sysctl.d/k8s.conf << EOF
3856net.bridge.bridge-nf-call-iptables = 1
3957net.bridge.bridge-nf-call-ip6tables = 1
@@ -47,6 +65,20 @@ modprobe overlay
4765modprobe br_netfilter
4866sysctl --system
4967
68+ # shellcheck disable=SC2174
69+ if ! mkdir -p -m 755 /etc/systemd/system.conf.d ; then
70+ echo " Error: Failed to create directory /etc/systemd/system.conf.d" >&2
71+ exit 1
72+ fi
73+
74+ cat > /etc/systemd/system.conf.d/override.conf << EOF
75+ [Manager]
76+ # Set sane defaults for the NOFILE limits to support high-performance workloads:
77+ # - Soft limit (65535): Suitable for most containerized applications.
78+ # - Hard limit (1048576): Allows scaling for high-demand scenarios.
79+ DefaultLimitNOFILE=65535:1048576
80+ EOF
81+
5082# containerd service
5183cat > /usr/lib/systemd/system/containerd.service << EOF
5284[Unit]
@@ -68,6 +100,7 @@ RestartSec=5
68100# in the kernel. We recommend using cgroups to do container-local accounting.
69101LimitNPROC=infinity
70102LimitCORE=infinity
103+ LimitNOFILE=infinity
71104
72105# Comment TasksMax if your systemd version does not supports it.
73106# Only systemd 226 and above support this version.
@@ -96,7 +129,12 @@ RestartSec=10
96129WantedBy=multi-user.target
97130EOF
98131
99- mkdir -p /usr/lib/systemd/system/kubelet.service.d
132+ # shellcheck disable=SC2174
133+ if ! mkdir -p -m 755 /usr/lib/systemd/system/kubelet.service.d ; then
134+ echo " Error: Failed to create directory /usr/lib/systemd/system/kubelet.service.d" >&2
135+ exit 1
136+ fi
137+
100138cat > /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf << EOF
101139# Note: This dropin only works with kubeadm and kubelet v1.11+
102140[Service]
@@ -116,36 +154,41 @@ swapoff -a
116154# check for required tools and only install missing tools
117155REQUIRED_TOOLS=(runc socat conntrack ethtool iptables)
118156INSTALL_TOOLS=()
119- for tool in ${REQUIRED_TOOLS[*]} ; do
157+ for tool in " ${REQUIRED_TOOLS[@]} " ; do
120158 echo " checking for ${tool} "
121- if [ ! -x " $( command -v ${tool} ) " ]; then
159+ if [ ! -x " $( command -v " ${tool} " ) " ]; then
122160 echo " ${tool} is missing"
123- INSTALL_TOOLS+=(${tool} )
161+ INSTALL_TOOLS+=(" ${tool} " )
124162 fi
125163done
126164export DEBIAN_FRONTEND=noninteractive
127165apt-get update -y
128- apt-get install -y ${INSTALL_TOOLS[*]}
166+ if [ " ${# INSTALL_TOOLS[@]} " -gt 0 ]; then
167+ apt-get install -y " ${INSTALL_TOOLS[@]} "
168+ fi
129169
130170# install containerd
131171curl -L " https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION} /containerd-${CONTAINERD_VERSION} -linux-amd64.tar.gz" | tar -C /usr/local -xz
132172
133173# install cni plugins
134- mkdir -p /opt/cni/bin
174+ if ! mkdir -p /opt/cni/bin ; then
175+ echo " Error: Failed to create directory /opt/cni/bin" >&2
176+ exit 1
177+ fi
178+
135179curl -L " https://github.com/containernetworking/plugins/releases/download/v${CNI_PLUGIN_VERSIONS} /cni-plugins-linux-amd64-v${CNI_PLUGIN_VERSIONS} .tgz" | tar -C /opt/cni/bin -xz
136180chown -R root:root /opt/cni
137181
138- PATCH_VERSION=${1# [v]}
139- VERSION=${PATCH_VERSION% .* }
140182
141183# install crictl
142184curl -L " https://github.com/kubernetes-sigs/cri-tools/releases/download/v${VERSION} .0/crictl-v${VERSION} .0-linux-amd64.tar.gz" | tar -C /usr/local/bin -xz
143185
144186# install kubeadm,kubelet,kubectl
145187cd /usr/local/bin
146- curl -L --remote-name-all https://dl.k8s.io/release/$1 /bin/linux/amd64/{kubeadm,kubelet}
188+ curl -L --remote-name-all " https://dl.k8s.io/release/$1 /bin/linux/amd64/{kubeadm,kubelet}"
147189curl -LO " https://dl.k8s.io/release/v${VERSION} .0/bin/linux/amd64/kubectl"
148190chmod +x {kubeadm,kubelet,kubectl}
191+
149192# reload systemd to pick up containerd & kubelet settings
150193systemctl daemon-reload
151194systemctl enable --now containerd kubelet
0 commit comments