Skip to content

Instantly share code, notes, and snippets.

@saiyam1814
Last active July 18, 2023 05:26
Show Gist options
  • Save saiyam1814/03700751b8d1068c18c942cf768ea26f to your computer and use it in GitHub Desktop.
Save saiyam1814/03700751b8d1068c18c942cf768ea26f to your computer and use it in GitHub Desktop.
kubernetes1.26.sh
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B53DC80D13EDEF05
echo "step1"
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
echo "kubeadm install"
sudo apt update -y
sudo apt -y install vim git curl wget kubelet=1.26.1-00 kubeadm=1.26.1-00 kubectl=1.26.1-00
echo "memory swapoff"
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo swapoff -a
sudo modprobe overlay
sudo modprobe br_netfilter
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
if (systemctl -q is-active containerd)
then
echo "containerd is still running."
rm /etc/containerd/config.toml
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 $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y containerd.io
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd
else
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 $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y containerd.io
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd
fi
sudo systemctl enable kubelet
sudo kubeadm config images pull --cri-socket unix:///run/containerd/containerd.sock --kubernetes-version v1.26.1
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --upload-certs --kubernetes-version=v1.26.1 --control-plane-endpoint=$(hostname) --ignore-preflight-errors=all --cri-socket unix:///run/containerd/containerd.sock
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=/etc/kubernetes/admin.conf
kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml
kubectl taint node $(hostname) node-role.kubernetes.io/control-plane:NoSchedule-
kubectl taint node $(hostname) node-role.kubernetes.io/master:NoSchedule-
wget https://get.helm.sh/helm-v3.7.2-linux-amd64.tar.gz
tar -xvf helm-v3.7.2-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/
@talhayameen
Copy link

nice work bro I have used it,

but its 4th time i am facing an issue regarding my coredns pods they are not starting due to tainat issue ,

Note : I am making my personal ubuntu as manager, I dont have any worker

@saiyam1814
Copy link
Author

Can you try these two commands ?

kubectl taint node $(hostname) node-role.kubernetes.io/control-plane:NoSchedule-
kubectl taint node $(hostname) node-role.kubernetes.io/master:NoSchedule-

Make sure to change the hostname

also run this to enable systemdcgroup (mandatory if its ubuntu 22.04)

sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml


@jessequinn
Copy link

how does this setup behave on reboot?

@saiyam1814
Copy link
Author

It should work! @jessequinn
Just tested that as well
Screenshot 2023-03-07 at 12 08 52 PM

@jessequinn
Copy link

Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "aa14a9a310688b10221a9c64bd38d909a42da2e7f5432aaaafacaaf0bbf8e081": plugin type="loopback" failed (add): failed to find plugin "loopback │
│ " in path [/opt/cni/bin]

@jessequinn
Copy link

Are you installing the CNI plugins at any point?

@saiyam1814
Copy link
Author

Line number 53 installs flannel
Also make sure to do

sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
systemctl restart containerd

@jessequinn
Copy link

jessequinn commented Mar 7, 2023

for me, i needed to do the following otherwise coredns would not run:

curl -fsSLo cni-plugins-linux-amd64-v1.1.1.tgz https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz
sudo mkdir -p /opt/cni/bin
sudo tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment