Skip to content

Commit

Permalink
✨ Backwards compatible support for containerd 2 (#1521)
Browse files Browse the repository at this point in the history
* feat: Backwards compatible support for containerd 2

* fix: Remove unnecessary chmod

* feat: Cleanup ARCH and add clusterd 2 support to packer templates

* fix: Revert removal of permissions change and update unit files
  • Loading branch information
emolitor authored Jan 7, 2025
1 parent ad99b29 commit 61ce827
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 42 deletions.
67 changes: 59 additions & 8 deletions templates/cluster-templates/bases/hcloud-kcp-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,77 @@ spec:
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 2606:4700:4700::1111
- content: |
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target dbus.service
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
owner: root:root
path: /etc/systemd/system/containerd.service
permissions: "0744"
preKubeadmCommands:
- set -x
- export CONTAINERD=1.7.24 # update: datasource=github-tags depName=containerd/containerd extractVersion=^v(?<version>.*)$ versioning=semver
- export RUNC=1.2.3
- export KUBERNETES_VERSION=$(echo ${KUBERNETES_VERSION} | sed 's/^v//')
- export TRIMMED_KUBERNETES_VERSION=$(echo ${KUBERNETES_VERSION} | sed 's/^v//' | awk -F . '{print $1 "." $2}')
- ARCH=amd64
- if [ "$(uname -m)" = "aarch64" ]; then ARCH=arm64; fi
- ARCH="$(dpkg --print-architecture)"
- localectl set-locale LANG=en_US.UTF-8
- localectl set-locale LANGUAGE=en_US.UTF-8
- apt-get update -y
- apt-get -y install at jq unzip wget socat mtr logrotate apt-transport-https
- sed -i '/swap/d' /etc/fstab
- swapoff -a
- modprobe overlay && modprobe br_netfilter && sysctl --system
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- sha256sum --check cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- tar --no-overwrite-dir -C / -xzf cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz
- rm -f cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- chmod -R 644 /etc/cni && chown -R root:root /etc/cni
- wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.$ARCH
- wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.sha256sum
- sha256sum --check --ignore-missing runc.sha256sum
- install runc.$ARCH /usr/local/sbin/runc
- rm -f runc.$ARCH runc.sha256sum
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- sha256sum --check containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- tar -zxf containerd-$CONTAINERD-linux-$ARCH.tar.gz -C /usr/local
- rm -f containerd-$CONTAINERD-linux-$ARCH.tar.gz containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- mkdir -p /etc/containerd
- containerd config default > /etc/containerd/config.toml
- sed -i "s/SystemdCgroup = false/SystemdCgroup = true/" /etc/containerd/config.toml
Expand Down
65 changes: 59 additions & 6 deletions templates/cluster-templates/bases/hetznerbaremetal-kcp-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,77 @@ spec:
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 2606:4700:4700::1111
- content: |
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target dbus.service
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
owner: root:root
path: /etc/systemd/system/containerd.service
permissions: "0744"
preKubeadmCommands:
- set -x
- export CONTAINERD=1.7.24 # update: datasource=github-tags depName=containerd/containerd extractVersion=^v(?<version>.*)$ versioning=semver
- export RUNC=1.2.3
- export KUBERNETES_VERSION=$(echo ${KUBERNETES_VERSION} | sed 's/^v//')
- export TRIMMED_KUBERNETES_VERSION=$(echo ${KUBERNETES_VERSION} | sed 's/^v//' | awk -F . '{print $1 "." $2}')
- ARCH="$(dpkg --print-architecture)"
- localectl set-locale LANG=en_US.UTF-8
- localectl set-locale LANGUAGE=en_US.UTF-8
- apt-get update -y
- apt-get -y install at jq unzip wget socat mtr logrotate apt-transport-https
- sed -i '/swap/d' /etc/fstab
- swapoff -a
- modprobe overlay && modprobe br_netfilter && sysctl --system
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/cri-containerd-cni-$CONTAINERD-linux-amd64.tar.gz
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/cri-containerd-cni-$CONTAINERD-linux-amd64.tar.gz.sha256sum
- sha256sum --check cri-containerd-cni-$CONTAINERD-linux-amd64.tar.gz.sha256sum
- tar --no-overwrite-dir -C / -xzf cri-containerd-cni-$CONTAINERD-linux-amd64.tar.gz
- rm -f cri-containerd-cni-$CONTAINERD-linux-amd64.tar.gz cri-containerd-cni-$CONTAINERD-linux-amd64.tar.gz.sha256sum
- chmod -R 644 /etc/cni && chown -R root:root /etc/cni
- wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.$ARCH
- wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.sha256sum
- sha256sum --check --ignore-missing runc.sha256sum
- install runc.$ARCH /usr/local/sbin/runc
- rm -f runc.$ARCH runc.sha256sum
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- sha256sum --check containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- tar -zxf containerd-$CONTAINERD-linux-$ARCH.tar.gz -C /usr/local
- rm -f containerd-$CONTAINERD-linux-$ARCH.tar.gz containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- mkdir -p /etc/containerd
- containerd config default > /etc/containerd/config.toml
- sed -i "s/SystemdCgroup = false/SystemdCgroup = true/" /etc/containerd/config.toml
Expand Down
67 changes: 59 additions & 8 deletions templates/cluster-templates/bases/kct-md-0-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,78 @@ spec:
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 2606:4700:4700::1111
- content: |
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target dbus.service
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
owner: root:root
path: /etc/systemd/system/containerd.service
permissions: "0744"
preKubeadmCommands:
- set -x
- grep VERSION= /etc/os-release; uname -a
- export CONTAINERD=1.7.24 # update: datasource=github-tags depName=containerd/containerd extractVersion=^v(?<version>.*)$ versioning=semver
- export RUNC=1.2.3
- export KUBERNETES_VERSION=$(echo ${KUBERNETES_VERSION} | sed 's/^v//')
- export TRIMMED_KUBERNETES_VERSION=$(echo ${KUBERNETES_VERSION} | sed 's/^v//' | awk -F . '{print $1 "." $2}')
- ARCH=amd64
- if [ "$(uname -m)" = "aarch64" ]; then ARCH=arm64; fi
- ARCH="$(dpkg --print-architecture)"
- localectl set-locale LANG=en_US.UTF-8
- localectl set-locale LANGUAGE=en_US.UTF-8
- apt-get update -y
- apt-get -y install at jq unzip wget socat mtr logrotate apt-transport-https
- sed -i '/swap/d' /etc/fstab
- swapoff -a
- modprobe overlay && modprobe br_netfilter && sysctl --system
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- sha256sum --check cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- tar --no-overwrite-dir -C / -xzf cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz
- rm -f cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz cri-containerd-cni-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- chmod -R 644 /etc/cni && chown -R root:root /etc/cni
- wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.$ARCH
- wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.sha256sum
- sha256sum --check --ignore-missing runc.sha256sum
- install runc.$ARCH /usr/local/sbin/runc
- rm -f runc.$ARCH runc.sha256sum
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz
- wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- sha256sum --check containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- tar -zxf containerd-$CONTAINERD-linux-$ARCH.tar.gz -C /usr/local
- rm -f containerd-$CONTAINERD-linux-$ARCH.tar.gz containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
- mkdir -p /etc/containerd
- containerd config default > /etc/containerd/config.toml
- sed -i "s/SystemdCgroup = false/SystemdCgroup = true/" /etc/containerd/config.toml
Expand Down
72 changes: 61 additions & 11 deletions templates/node-image/1.28.9-ubuntu-22-04-containerd/scripts/cri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,75 @@ kernel.panic=10
kernel.panic_on_oops=1
EOF

# Create containerd systemd unit
cat >/etc/systemd/system/containerd.service <<'EOF'
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target dbus.service
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF

# Apply sysctl params without reboot
sysctl --system

ARCH="$(dpkg --print-architecture)"
CONTAINERD=1.7.16 # https://github.com/containerd/containerd/releases
RUNC=1.2.3 # https://github.com/opencontainers/runc/releases

# Install runc
wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.$ARCH
wget https://github.com/opencontainers/runc/releases/download/v$RUNC/runc.sha256sum
sha256sum --check --ignore-missing runc.sha256sum
install runc.$ARCH /usr/local/sbin/runc

# Install containerd
wget https://github.com/containerd/containerd/releases/download/v${CONTAINERD}/cri-containerd-cni-${CONTAINERD}-linux-${PACKER_ARCH}.tar.gz
wget https://github.com/containerd/containerd/releases/download/v${CONTAINERD}/cri-containerd-cni-${CONTAINERD}-linux-${PACKER_ARCH}.tar.gz.sha256sum
sha256sum --check cri-containerd-cni-${CONTAINERD}-linux-${PACKER_ARCH}.tar.gz.sha256sum
tar --no-overwrite-dir -C / -xzf cri-containerd-cni-${CONTAINERD}-linux-${PACKER_ARCH}.tar.gz
wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz
wget https://github.com/containerd/containerd/releases/download/v$CONTAINERD/containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
sha256sum --check containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum
tar -zxf containerd-$CONTAINERD-linux-$ARCH.tar.gz -C /usr/local

# Cleanup
rm -f cri-containerd-cni-${CONTAINERD}-linux-${PACKER_ARCH}.tar.gz cri-containerd-cni-${CONTAINERD}-linux-${PACKER_ARCH}.tar.gz.sha256sum

mkdir -p /etc/containerd

# Sets permission accordingly to CIS Benchmark
chmod -R 644 /etc/cni
chown -R root:root /etc/cni
rm -f runc.$ARCH runc.sha256sum
rm -f containerd-$CONTAINERD-linux-$ARCH.tar.gz containerd-$CONTAINERD-linux-$ARCH.tar.gz.sha256sum

mkdir -p /etc/containerd
containerd config default >/etc/containerd/config.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ systemctl enable kubelet

kubeadm config images pull --kubernetes-version $KUBERNETES_VERSION

# Sets permission accordingly to CIS Benchmark
chmod -R 644 /etc/cni
chown -R root:root /etc/cni

# enable completion
echo 'source <(kubectl completion bash)' >>/root/.bashrc

Expand Down
Loading

0 comments on commit 61ce827

Please sign in to comment.