Kubeadm create k8s cluster

Requirement:

Master: Ubuntu 20.04, 8192Mb RAM, 4core CPU

Worker: Ubuntu 20.04, 4096Mb RAM, 2core CPU

Install CRI (containerd)

update all machine

$ sudo apt update 

install docker dependency and add repo

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

install containerd

$ sudo apt install containerd.io

install kubeadm

All nodes

use super user

$ sudo -s

set all swap off

# swapoff -a

Remove any matching reference found in /etc/fstab

# vi /etc/fstab

# ***** /swap

Or
# sudo sed -i ‘/\tswap\t/d’ /etc/fstab

update

# apt update

install kubernetes dependency and add repo

# apt install -y apt-transport-https curl
# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
# echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list

update

# apt update

install and mark hold kubeadm, kubectl, kubelet

# apt install -y kubeadm kubectl kubelet
# apt-mark hold kubeadm kubectl kubelet

modprobe machine

# modprobe overlay
# modprobe br_netfilter

set containerd module

# cat > /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

set kubernetes cri

# cat <<EOF | tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

check system status

# sysctl --system

make conteinerd directory service

# mkdir -p /etc/systemd/system/containerd.service.d

config override containerd

# cat <<EOF | tee /etc/systemd/system/containerd.service.d/override.conf
[Service]
LimitMEMLOCK=4194304
LimitNOFILE=1048576
EOF

remove old containerd configuration

# rm /etc/containerd/config.toml

restart containerd service

# systemctl restart containerd

On MASTER NODE

run init

# kubeadm init --pod-network-cidr=10.244.0.0/16

run the following as a regular user

# mkdir /root/.kube
# cp /etc/kubernetes/admin.conf /root/.kube/config
# chown $(id -u):$(id -g) /root/.kube/config

now deploy a pod network to the cluster.

Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:

https://kubernetes.io/docs/concepts/cluster-administration/addons/

use flannel as CNI

# kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

check node status
# kubectl get node

on WORKER NODE

Then you can join any number of worker nodes by running the following on each as root

# kubeadm join --token <token> <ip>:6443 --token ****

sample:

kubeadm join 10.99.9.31:6443 --token e5grz5.93by9mynh81czr48 \
        --discovery-token-ca-cert-hash sha256:7a255ed8fcb178f435acb542cfea7b3554e2c1e08b54c97f2f8a66699d2ca0ea

Leave a Reply

Your email address will not be published. Required fields are marked *