Created
May 16, 2021 13:29
-
-
Save avoidik/ae62f8e114aaf105536b844daa58807e to your computer and use it in GitHub Desktop.
How to use containerd with conf_template option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DASEL_VER="1.15.0" | |
CRI_VER="1.5.1" | |
# | |
# install dasel | |
# | |
curl -fsSL "https://github.com/TomWright/dasel/releases/download/v${DASEL_VER}/dasel_linux_amd64" -o /usr/local/bin/dasel | |
chmod +x /usr/local/bin/dasel | |
# | |
# install containerd, excluding default 10-containerd-net.conflist | |
# | |
curl -fsSL "https://github.com/containerd/containerd/releases/download/v${CRI_VER}/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz" -o "/tmp/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz" | |
curl -fsSL "https://github.com/containerd/containerd/releases/download/v${CRI_VER}/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz.sha256sum" -o "/tmp/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz.sha256sum" | |
(cd /tmp && sha256sum --check "/tmp/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz.sha256sum") | |
tar --no-overwrite-dir -C / -xzf "/tmp/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz" --exclude='etc/cni/net.d/10-containerd-net.conflist' | |
rm -f "/tmp/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz" "/tmp/cri-containerd-cni-${CRI_VER}-linux-amd64.tar.gz.sha256sum" | |
# | |
# prepare configuration | |
# | |
mkdir -p /etc/containerd | |
containerd config default | tee /etc/containerd/config.toml | |
cat <<'EOF' | tee /etc/containerd/cni.template | |
{ | |
"name": "cbr0", | |
"cniVersion": "0.3.1", | |
"plugins": [ | |
{ | |
"type": "flannel", | |
"delegate": { | |
"hairpinMode": true, | |
"isDefaultGateway": true | |
}, | |
"ipam": { | |
"type": "host-local", | |
"ranges": [{{range $i, $range := .PodCIDRRanges}}{{if $i}}, {{end}}[{"subnet": "{{$range}}"}]{{end}}], | |
"routes": [{{range $i, $route := .Routes}}{{if $i}}, {{end}}{"dst": "{{$route}}"}{{end}}] | |
} | |
}, | |
{ | |
"type": "portmap", | |
"capabilities": { | |
"portMappings": true | |
} | |
} | |
] | |
} | |
EOF | |
# change conf_template | |
dasel put string -f /etc/containerd/config.toml -p toml '.plugins.io\.containerd\.grpc\.v1\.cri.cni.conf_template' '/etc/containerd/cni.template' | |
# change SystemdCgroup | |
dasel put bool -f /etc/containerd/config.toml -p toml '.plugins.io\.containerd\.grpc\.v1\.cri.containerd.runtimes.runc.options.SystemdCgroup' 'true' | |
# | |
# enable containerd service | |
# | |
systemctl daemon-reload | |
systemctl reenable containerd.service | |
systemctl restart containerd.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment