1
1
#! /bin/bash
2
2
set -euo pipefail
3
+
3
4
DEFAULT_CONTAINERD_VERSION=1.7.24
4
5
DEFAULT_CNI_PLUGIN_VERSIONS=1.6.2
5
6
CONTAINERD_VERSION=" ${CONTAINERD_VERSION:= $DEFAULT_CONTAINERD_VERSION } "
6
7
CNI_PLUGIN_VERSIONS=" ${CNI_PLUGIN_VERSIONS:= $DEFAULT_CNI_PLUGIN_VERSIONS } "
7
8
8
9
# 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
+
10
16
cat > /etc/containerd/config.toml << EOF
11
17
version = 2
12
18
imports = ["/etc/containerd/conf.d/*.toml"]
25
31
26
32
chmod 644 /etc/containerd/config.toml
27
33
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
+
29
40
cat > /etc/modules-load.d/k8s.conf << EOF
30
41
overlay
31
42
br_netfilter
32
43
EOF
33
44
34
45
chmod 644 /etc/modules-load.d/k8s.conf
35
46
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
+
37
53
cat > /etc/sysctl.d/k8s.conf << EOF
38
54
net.bridge.bridge-nf-call-iptables = 1
39
55
net.bridge.bridge-nf-call-ip6tables = 1
@@ -47,6 +63,20 @@ modprobe overlay
47
63
modprobe br_netfilter
48
64
sysctl --system
49
65
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
+
50
80
# containerd service
51
81
cat > /usr/lib/systemd/system/containerd.service << EOF
52
82
[Unit]
@@ -68,6 +98,7 @@ RestartSec=5
68
98
# in the kernel. We recommend using cgroups to do container-local accounting.
69
99
LimitNPROC=infinity
70
100
LimitCORE=infinity
101
+ LimitNOFILE=infinity
71
102
72
103
# Comment TasksMax if your systemd version does not supports it.
73
104
# Only systemd 226 and above support this version.
@@ -96,7 +127,12 @@ RestartSec=10
96
127
WantedBy=multi-user.target
97
128
EOF
98
129
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
+
100
136
cat > /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf << EOF
101
137
# Note: This dropin only works with kubeadm and kubelet v1.11+
102
138
[Service]
@@ -116,22 +152,26 @@ swapoff -a
116
152
# check for required tools and only install missing tools
117
153
REQUIRED_TOOLS=(runc socat conntrack ethtool iptables)
118
154
INSTALL_TOOLS=()
119
- for tool in ${REQUIRED_TOOLS[*]} ; do
155
+ for tool in " ${REQUIRED_TOOLS[@]} " ; do
120
156
echo " checking for ${tool} "
121
- if [ ! -x " $( command -v ${tool} ) " ]; then
157
+ if [ ! -x " $( command -v " ${tool} " ) " ]; then
122
158
echo " ${tool} is missing"
123
- INSTALL_TOOLS+=(${tool} )
159
+ INSTALL_TOOLS+=(" ${tool} " )
124
160
fi
125
161
done
126
162
export DEBIAN_FRONTEND=noninteractive
127
163
apt-get update -y
128
- apt-get install -y ${INSTALL_TOOLS[*]}
164
+ apt-get install -y " ${INSTALL_TOOLS[@]} "
129
165
130
166
# install containerd
131
167
curl -L " https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION} /containerd-${CONTAINERD_VERSION} -linux-amd64.tar.gz" | tar -C /usr/local -xz
132
168
133
169
# 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
+
135
175
curl -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
136
176
chown -R root:root /opt/cni
137
177
@@ -143,9 +183,10 @@ curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${VERSI
143
183
144
184
# install kubeadm,kubelet,kubectl
145
185
cd /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}"
147
187
curl -LO " https://dl.k8s.io/release/v${VERSION} .0/bin/linux/amd64/kubectl"
148
188
chmod +x {kubeadm,kubelet,kubectl}
189
+
149
190
# reload systemd to pick up containerd & kubelet settings
150
191
systemctl daemon-reload
151
192
systemctl enable --now containerd kubelet
0 commit comments