Skip to content

Instantly share code, notes, and snippets.

@dipankardas011
Created June 10, 2023 11:39
Show Gist options
  • Save dipankardas011/c9cab1a68c800cc9a086f7ebeb6700b2 to your computer and use it in GitHub Desktop.
Save dipankardas011/c9cab1a68c800cc9a086f7ebeb6700b2 to your computer and use it in GitHub Desktop.
kubeadm HA
###########################
# IT IS ONLY
# INSTRUCTIONS (NOT MENT TO BE EXECUTABLE DIRECTLY)
###########################
# reference: https://gist.github.com/saiyam1814/c3e91322441fdb53bbf5958b943a41f3
# 192.168.1.6 kubeadm-cp-1-5db6-f1562d
# 192.168.1.7 kubeadm-cp-2-11ce-f1562d
# 192.168.1.8 kubeadm-cp-3-16c3-f1562d
############ RUN THESE FOR ALL KUBERNETES NODES (controlplane and workerplane)
echo "step1- install kubectl,kubeadm and kubelet 1.27.1"
# export DEBIAN_FRONTEND='noninteractive'
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
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.27.1-00 kubeadm=1.27.1-00 kubectl=1.27.1-00
echo "memory swapoff"
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo swapoff -a
sudo modprobe overlay
sudo modprobe br_netfilter
echo "Containerd setup"
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
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update -y
echo -ne '\n' | sudo apt-get -y install containerd
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable kubelet
echo "image pull and cluster setup"
sudo kubeadm config images pull --cri-socket unix:///run/containerd/containerd.sock --kubernetes-version v1.27.1
###########################
######### CONFIGURE THE CONTROLPLANE ##########
# add the dns entries in /etc/hosts for each controlplane (not itself) and its hostname and private IP
#### For CONTROLPLANE (1)
sudo kubeadm init --apiserver-advertise-address=0.0.0.0 --apiserver-cert-extra-sans=<lb-public> --pod-network-cidr=10.244.0.0/16 --upload-certs --kubernetes-version=v1.27.1 --control-plane-endpoint=$(hostname) --ignore-preflight-errors=all --cri-socket unix:///run/containerd/containerd.sock
# for the join to work add the entry of the controlplane node and loadbalancer to each /etc/hosts
#### For the CONTROLPLANNE (2...n)
sudo kubeadm join.....
#### for the workerplane (1..m)
sudo kubeadm join ....
# the above commands wil lbe provided when you ran the kubeadm init command for the first time
#### for the CNI ####
echo "Apply flannel network"
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-
###### for the configuration of loadblanacer #####
apt install haproxy -y
systemctl start haproxy && systemctl enable haproxy
cat <<EOF > /etc/haproxy/haproxy.cfg
frontend kubernetes-frontend
bind *:6443
mode tcp
option tcplog
timeout client 10s
default_backend kubernetes-backend
backend kubernetes-backend
timeout connect 10s
timeout server 10s
mode tcp
option tcp-check
balance roundrobin
server k3sserver1 <privateip>:6443
server k3sserver2 <privateip>:6443
EOF
systemctl restart haproxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment