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 } "
78
89# setup containerd config
9- mkdir -p -m 755 /etc/containerd
10+ # shellcheck disable=SC2174
11+ if ! mkdir -p -m 755 /etc/containerd ; then
12+ echo " Error: Failed to create directory /etc/containerd" >&2
13+ exit 1
14+ fi
15+
1016cat > /etc/containerd/config.toml << EOF
1117version = 2
1218imports = ["/etc/containerd/conf.d/*.toml"]
2531
2632chmod 644 /etc/containerd/config.toml
2733
28- mkdir -p -m 755 /etc/modules-load.d
34+ # shellcheck disable=SC2174
35+ if ! mkdir -p -m 755 /etc/modules-load.d ; then
36+ echo " Error: Failed to create directory /etc/modules-load.d" >&2
37+ exit 1
38+ fi
39+
2940cat > /etc/modules-load.d/k8s.conf << EOF
3041overlay
3142br_netfilter
3243EOF
3344
3445chmod 644 /etc/modules-load.d/k8s.conf
3546
36- mkdir -p -m 755 /etc/sysctl.d
47+ # shellcheck disable=SC2174
48+ if ! mkdir -p -m 755 /etc/sysctl.d ; then
49+ echo " Error: Failed to create directory /etc/sysctl.d" >&2
50+ exit 1
51+ fi
52+
3753cat > /etc/sysctl.d/k8s.conf << EOF
3854net.bridge.bridge-nf-call-iptables = 1
3955net.bridge.bridge-nf-call-ip6tables = 1
@@ -47,6 +63,20 @@ modprobe overlay
4763modprobe br_netfilter
4864sysctl --system
4965
66+ # shellcheck disable=SC2174
67+ if ! mkdir -p -m 755 /etc/systemd/system.conf.d ; then
68+ echo " Error: Failed to create directory /etc/systemd/system.conf.d" >&2
69+ exit 1
70+ fi
71+
72+ cat > /etc/systemd/system.conf.d/override.conf << EOF
73+ [Manager]
74+ # Set sane defaults for the NOFILE limits to support high-performance workloads:
75+ # - Soft limit (65535): Suitable for most containerized applications.
76+ # - Hard limit (1048576): Allows scaling for high-demand scenarios.
77+ DefaultLimitNOFILE=65535:1048576
78+ EOF
79+
5080# containerd service
5181cat > /usr/lib/systemd/system/containerd.service << EOF
5282[Unit]
@@ -68,6 +98,7 @@ RestartSec=5
6898# in the kernel. We recommend using cgroups to do container-local accounting.
6999LimitNPROC=infinity
70100LimitCORE=infinity
101+ LimitNOFILE=infinity
71102
72103# Comment TasksMax if your systemd version does not supports it.
73104# Only systemd 226 and above support this version.
@@ -96,7 +127,12 @@ RestartSec=10
96127WantedBy=multi-user.target
97128EOF
98129
99- mkdir -p /usr/lib/systemd/system/kubelet.service.d
130+ # shellcheck disable=SC2174
131+ if ! mkdir -p -m 755 /usr/lib/systemd/system/kubelet.service.d ; then
132+ echo " Error: Failed to create directory /usr/lib/systemd/system/kubelet.service.d" >&2
133+ exit 1
134+ fi
135+
100136cat > /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf << EOF
101137# Note: This dropin only works with kubeadm and kubelet v1.11+
102138[Service]
@@ -116,22 +152,26 @@ swapoff -a
116152# check for required tools and only install missing tools
117153REQUIRED_TOOLS=(runc socat conntrack ethtool iptables)
118154INSTALL_TOOLS=()
119- for tool in ${REQUIRED_TOOLS[*]} ; do
155+ for tool in " ${REQUIRED_TOOLS[@]} " ; do
120156 echo " checking for ${tool} "
121- if [ ! -x " $( command -v ${tool} ) " ]; then
157+ if [ ! -x " $( command -v " ${tool} " ) " ]; then
122158 echo " ${tool} is missing"
123- INSTALL_TOOLS+=(${tool} )
159+ INSTALL_TOOLS+=(" ${tool} " )
124160 fi
125161done
126162export DEBIAN_FRONTEND=noninteractive
127163apt-get update -y
128- apt-get install -y ${INSTALL_TOOLS[*]}
164+ apt-get install -y " ${INSTALL_TOOLS[@]} "
129165
130166# install containerd
131167curl -L " https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION} /containerd-${CONTAINERD_VERSION} -linux-amd64.tar.gz" | tar -C /usr/local -xz
132168
133169# install cni plugins
134- mkdir -p /opt/cni/bin
170+ if ! mkdir -p /opt/cni/bin ; then
171+ echo " Error: Failed to create directory /opt/cni/bin" >&2
172+ exit 1
173+ fi
174+
135175curl -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
136176chown -R root:root /opt/cni
137177
@@ -143,9 +183,10 @@ curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${VERSI
143183
144184# install kubeadm,kubelet,kubectl
145185cd /usr/local/bin
146- curl -L --remote-name-all https://dl.k8s.io/release/$1 /bin/linux/amd64/{kubeadm,kubelet}
186+ curl -L --remote-name-all " https://dl.k8s.io/release/$1 /bin/linux/amd64/{kubeadm,kubelet}"
147187curl -LO " https://dl.k8s.io/release/v${VERSION} .0/bin/linux/amd64/kubectl"
148188chmod +x {kubeadm,kubelet,kubectl}
189+
149190# reload systemd to pick up containerd & kubelet settings
150191systemctl daemon-reload
151192systemctl enable --now containerd kubelet
0 commit comments