Bootstraping kubernetes with containerd

I am using ubuntu 16.04 to build the kubernetes cluster with the following information:

  • 10.200.200.130 zu-k8s-containerd-master
  • 10.200.200.140 zu-k8s-containerd-worker

The first thing is add name resolution

sudo nano /etc/hosts

10.200.200.130 zu-k8s-containerd-master
10.200.200.140 zu-k8s-containerd-worker

Install containerd

apt-get update && apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

apt-get update && apt-get install -y containerd.io

mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

edit some network linux configuration

modprobe br_netfilter
cat <<EOF >>  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
sudo sysctl -p

restart containerd

systemctl restart containerd

Install kubernetes

sudo apt install -y apt-transport-https; curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat << EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF

sudo apt update; sudo apt install -y kubectl kubelet kubeadm
apt-mark hold kubelet kubeadm kubectl

Modify kubelet to use containerd

cat <<EOF > /etc/systemd/system/kubelet.service.d/0-containerd.conf
[Service]                                                 
Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock"
EOF

systemctl daemon-reload
systemctl restart kubelet

Bootstraping kubernetes on master

swapon -s
sudo swapoff -a
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

create config directory for kubectl

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

install CNI, the example is flannel

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
kubectl get pods --all-namespaces --watch

Join worker, this script is generated with kubeadm init

swapon -s
sudo swapoff -a
kubeadm join 10.200.200.130:6443 --token j2pap8.t0cji20hoygrw6hr \
    --discovery-token-ca-cert-hash sha256:2b34395e2f7b4a997572332aa77a07609dcf9dd7f12460605e4f7497c72565d1

Comments are closed.