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 } "
8
+ PATCH_VERSION=${1# [v]}
9
+ VERSION=${PATCH_VERSION% .* }
7
10
8
11
# 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
+
10
18
cat > /etc/containerd/config.toml << EOF
11
19
version = 2
12
20
imports = ["/etc/containerd/conf.d/*.toml"]
25
33
26
34
chmod 644 /etc/containerd/config.toml
27
35
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
+
29
42
cat > /etc/modules-load.d/k8s.conf << EOF
30
43
overlay
31
44
br_netfilter
32
45
EOF
33
46
34
47
chmod 644 /etc/modules-load.d/k8s.conf
35
48
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
+
37
55
cat > /etc/sysctl.d/k8s.conf << EOF
38
56
net.bridge.bridge-nf-call-iptables = 1
39
57
net.bridge.bridge-nf-call-ip6tables = 1
@@ -47,6 +65,20 @@ modprobe overlay
47
65
modprobe br_netfilter
48
66
sysctl --system
49
67
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
+
50
82
# containerd service
51
83
cat > /usr/lib/systemd/system/containerd.service << EOF
52
84
[Unit]
@@ -68,6 +100,7 @@ RestartSec=5
68
100
# in the kernel. We recommend using cgroups to do container-local accounting.
69
101
LimitNPROC=infinity
70
102
LimitCORE=infinity
103
+ LimitNOFILE=infinity
71
104
72
105
# Comment TasksMax if your systemd version does not supports it.
73
106
# Only systemd 226 and above support this version.
@@ -96,7 +129,12 @@ RestartSec=10
96
129
WantedBy=multi-user.target
97
130
EOF
98
131
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
+
100
138
cat > /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf << EOF
101
139
# Note: This dropin only works with kubeadm and kubelet v1.11+
102
140
[Service]
@@ -116,36 +154,40 @@ swapoff -a
116
154
# check for required tools and only install missing tools
117
155
REQUIRED_TOOLS=(runc socat conntrack ethtool iptables)
118
156
INSTALL_TOOLS=()
119
- for tool in ${REQUIRED_TOOLS[*]} ; do
157
+ for tool in " ${REQUIRED_TOOLS[@]} " ; do
120
158
echo " checking for ${tool} "
121
- if [ ! -x " $( command -v ${tool} ) " ]; then
159
+ if [ ! -x " $( command -v " ${tool} " ) " ]; then
122
160
echo " ${tool} is missing"
123
- INSTALL_TOOLS+=(${tool} )
161
+ INSTALL_TOOLS+=(" ${tool} " )
124
162
fi
125
163
done
126
164
export DEBIAN_FRONTEND=noninteractive
127
165
apt-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
129
169
130
170
# install containerd
131
171
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
172
133
173
# 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
+
135
179
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
180
chown -R root:root /opt/cni
137
181
138
- PATCH_VERSION=${1# [v]}
139
- VERSION=${PATCH_VERSION% .* }
140
-
141
182
# install crictl
142
183
curl -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
143
184
144
185
# install kubeadm,kubelet,kubectl
145
186
cd /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}"
147
188
curl -LO " https://dl.k8s.io/release/v${VERSION} .0/bin/linux/amd64/kubectl"
148
189
chmod +x {kubeadm,kubelet,kubectl}
190
+
149
191
# reload systemd to pick up containerd & kubelet settings
150
192
systemctl daemon-reload
151
193
systemctl enable --now containerd kubelet
0 commit comments