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+ if ! mkdir -p /etc/containerd ; then
13+ echo " Error: Failed to create directory /etc/containerd" >&2
14+ exit 1
15+ fi
16+ chmod 0755 /etc/containerd
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+ if ! mkdir -p /etc/modules-load.d ; then
37+ echo " Error: Failed to create directory /etc/modules-load.d" >&2
38+ exit 1
39+ fi
40+ chmod 0755 /etc/modules-load.d
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+ if ! mkdir -p /etc/sysctl.d ; then
50+ echo " Error: Failed to create directory /etc/sysctl.d" >&2
51+ exit 1
52+ fi
53+ chmod 0755 /etc/sysctl.d
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+ if ! mkdir -p /etc/systemd/system.conf.d ; then
69+ echo " Error: Failed to create directory /etc/systemd/system.conf.d" >&2
70+ exit 1
71+ fi
72+ chmod 0755 /etc/systemd/system.conf.d
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+ if ! mkdir -p /usr/lib/systemd/system/kubelet.service.d ; then
133+ echo " Error: Failed to create directory /usr/lib/systemd/system/kubelet.service.d" >&2
134+ exit 1
135+ fi
136+ chmod 0755 /usr/lib/systemd/system/kubelet.service.d
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,40 @@ 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% .* }
140-
141182# install crictl
142183curl -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
143184
144185# install kubeadm,kubelet,kubectl
145186cd /usr/local/bin
146- curl -L --remote-name-all https://dl.k8s.io/release/$1 /bin/linux/amd64/{kubeadm,kubelet}
187+ curl -L --remote-name-all " https://dl.k8s.io/release/$1 /bin/linux/amd64/{kubeadm,kubelet}"
147188curl -LO " https://dl.k8s.io/release/v${VERSION} .0/bin/linux/amd64/kubectl"
148189chmod +x {kubeadm,kubelet,kubectl}
190+
149191# reload systemd to pick up containerd & kubelet settings
150192systemctl daemon-reload
151193systemctl enable --now containerd kubelet
0 commit comments