Skip to content

Instantly share code, notes, and snippets.

@moycat
Created January 23, 2022 10:34
Show Gist options
  • Save moycat/3a53c2e03b7f40e60d0a39c856ec4041 to your computer and use it in GitHub Desktop.
Save moycat/3a53c2e03b7f40e60d0a39c856ec4041 to your computer and use it in GitHub Desktop.
A script to install Kubernetes with continerd.
#!/bin/bash -e
VERSION=1.23.2
PROXY=""
cat <<EOF > /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
cat <<EOF > /etc/sysctl.d/99-containerd.conf
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.ipv6.conf.all.forwarding=1
net.ipv4.ip_forward=1
EOF
sysctl --system
export http_proxy="${PROXY}" https_proxy="${PROXY}"
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
add-apt-repository "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main"
apt-get update
apt-get install -y --allow-change-held-packages \
containerd.io kubelet=${VERSION}-00 kubeadm=${VERSION}-00 kubectl=${VERSION}-00
apt-mark hold kubelet kubeadm kubectl
containerd config default > /etc/containerd/config.toml
sed -i 's/containerd.runtimes.runc.options\]/containerd.runtimes.runc.options]\n SystemdCgroup = true/g' /etc/containerd/config.toml
mkdir -p /etc/systemd/system/containerd.service.d
cat >/etc/systemd/system/containerd.service.d/proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=${PROXY}" "HTTPS_PROXY=${PROXY}" "NO_PROXY=127.0.0.1/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,::1/128,fc00::/7"
EOF
systemctl daemon-reload
systemctl restart containerd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment