# kubeadm install:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
# disable swap right now, for kubeadm init to work:
sudo swapoff -a
# disable swap after next reboot as well
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
systemctl mask swap.target
# restart kubelet
sudo systemctl restart kubelet
# initialize:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --skip-phases=addon/kube-proxy
# if you see this error:
#
# [ERROR CRI]: container runtime is not running: output: time="2...
#
sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd
# initialize again, this time it should work. It'll take about 5 minutes.
sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --skip-phases=addon/kube-proxy
# if you messed up and want to purge the kubeadm setup and run again sudo kubeadm init, run:
sudo kubeadm reset
y
# if you see this error, because why would it work in the first try anyways:
#
# error execution phase addon/kube-proxy: error when creating kube-proxy RBAC rules: unable to create RBAC
# clusterrolebinding: Post "https:// YOURIP :6443/apis/rbac.authorization.k8s.io/v1/clusterrolebindings?timeout=10s":
# dial tcp 10.1.10.16:6443: connect: connection refused
#
# then run it with this flag:
#
sudo kubeadm reset
y
sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --skip-phases=addon/kube-proxy
# if kubeadm is good, continue
# add flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# allow user to run k8s stuff, run these commands as it tells you at the end of the kubeadm init. Make sure you're not ROOT:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=$HOME/admin.conf
# set up autocompletion:
sudo apt-get install bash-completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
# add misc
echo "alias k='kubectl'" >> ~/.bashrc
echo 'export KUBECONFIG=$HOME/admin.conf' >> $HOME/.bashrc
source ~/.bashrc
# test it:
sudo swapoff -a && kubectl get all
# Note: after every re-install, reset, init, always re-run this as your user (not as root):
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=$HOME/admin.conf