Install Kubernetes Cluster using kubeadm (Part-I)
ဒီနေ့မှာတော့ ကျွန်တော် ubuntu 20.04 server (3) ခုပေါ်မှာ kubernetes cluster တစ်ခုကို kubeadm နဲ့ install လုပ်ပြပြီး nginx pod တစ်ခုရယ် nginx deployment တစ်ခုရယ် deploy လုပ်ပြပါမယ်။ Kubernetes ဆိုတာ containerized applications တွေကို deployလုပ်ခြင်း scaling လုပ်ခြင်း စသည့် operations တွေကို automate လုပ်မယ့် tool ပါ။ အခုပဲ LAB လေးကိုစလိုက်ကြရအောင်နော်။
ပထမဆုံးအနေနဲ့ master နဲ့ worker nodes တွေထဲကို root user အနေနဲ့ login ဝင်ထားပေးပါ။ server (၃)ခုလုံးအတွက် terminal ကနေ အောက်က command ကိုရိုက်လိုက်ပါ။
sudo su -
ဒုတိယအဆင့်ကတော့ firewall ကို server (၃)ခုလုံးအတွက်ပိတ်ထားပေးပါ။ ( on all nodes )
ufw disable
တတိယအဆင့်မှာ server (၃)ခုလုံးအတွက် swap ကိုပိတ်ထားပေးပါ။ ( on all nodes )
swapoff -a; sed -i '/swap/d' /etc/fstab
kubernetes networking အတွက် sysctl ကို update လုပ်ပေးပါ။ ( on all nodes )
cat >>/etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
docker ကို server အကုန်လုံးမှာ သွင်းပေးပါ။ ( on all nodes )
{
apt update -y
apt install -y docker-io containerd.io
}
နောက်တစ်ဆင့်ကတော့ kubernetes install ဖို့အတွက် apt repo key ကို server အကုန်လုံးမှာ add ပေးပါ။ ( on all nodes )
{
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
}
နောက်တစ်ဆင့်ကတော့ kubernetes components တွေကို server အကုန်လုံးမှာ install လုပ်ပေးပါ။ ( on all nodes )
apt update && apt install -y kubeadm=1.18.5-00 kubelet=1.18.5-00 kubectl=1.18.5-00
Initialize K8s Cluster On Master
master node ပေါ်မှာ kubeadm init နဲ့ kubernetes cluster တစ်ခုကို initialize လုပ်ပေးပါ။ api-advertise-address သည် ကျွန်တော်တို့ k8s cluster မှာ master အဖြစ်သုံးမယ့် server ရဲ့ ip address ဖြစ်ပါတယ်။ ကျွန်တော်ရဲ့ lab မှာ master node ရဲ့ ip က 10.0.0.4 ပါ။ pod-network-cidr က ကျွန်တော်တို့ cluster ထဲမှာ run မယ့် pods တွေရဲ့ cidr block ပါ။ ဒီ lab မှာတော့ class c ရဲ့ private subnet ကိုသုံးထားပါတယ်။ ( on master )
kubeadm init --apiserver-advertise-address=172.16.16.100 --pod-network-cidr=192.168.0.0/16 --ignore-preflight-errors=all
မိမိရဲ့ internet connection ပေါ်မူတည်ပြီး ၁၀မိနစ် ကနေ မိနစ်၂၀ အထိကြာနိုင်ပါတယ်။ နောက်ဆုံးမှာ အောက်ကလို token တစ်ခုထွက်လာပါလိမ့်မယ်။
To start using your cluster, you need to run (as a regular user):
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
http://kubernetes.io/docs/admin/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join --token 354502.d6a9a425d5fa8f2e 10.0.0.4:6443 --discovery-token-ca-cert-hash
sha256:ad7c5e8a0c909ed36a87452e65fa44b1c2a9729cef7285eb551e2f126a1d6a54
master node မှာပဲ kubeconfig file ကို ကျွန်တော်တို့ရဲ့ home အောက်က .kube directory ထဲကို အောက်ကလို ကူးထည့်ပေးပါ။ ( on master )
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
ပြီးရင်တော့ CNI network plugin တစ်ခုခုကို install ပေးရပါမယ်။ ကျွန်တာ်ကတော့ calico ကိုပဲ သုံးထားပါတယ်။ ( on master )
kubectl --kubeconfig=/etc/kubernetes/admin.conf create -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
ပြီးရင်တော့ k8s cluster မှာ worker nodes တွေ join ဖို့အတွက် လိုအပ်တဲ့ token ကိုရဖို့ master node မှာ အောက်က command ကို run ပေးပါ။ kubeadm init run လိုက်လို့ထွက်လာတဲ့ နောက်ဆုံးက token နဲ့အတူတူပါပဲ။ ( on master )
kubeadm token create --print-join-command
Join Worker Nodes To K8s Cluster
ရလာတဲ့ token ကို worker nodes အဖြစ်သုံးမယ့် ကျန် server ၂ခုပေါ်မှာ run လိုက်ပါ။ ဒါဆိုရင် kubeadm ကို သုံးပြီး kubernetes cluster တစ်ခုဆောက်တာပြီးဆုံးသွားပါပြီ။
kubectl နဲ့ဆိုင်တဲ့ command တွေကို master node မှာပဲ run ရမှာပါ။ nodes တွေရဲ့ အခြေအနေကိုသိရဖို့ kubectl get nodes နဲ့ ကြည့်လိုက်ပါ။
root@kmaster:~# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
kmaster Ready control-plane,master 55m v1.20.0 10.0.0.4 <none> Ubuntu 20.04.2 LTS 5.4.0-1047-azure docker://20.10.6
kworker1 Ready <none> 51m v1.20.0 10.0.0.5 <none> Ubuntu 20.04.2 LTS 5.4.0-1047-azure docker://20.10.6
kworker2 Ready <none> 51m v1.20.0 10.0.0.6 <none> Ubuntu 20.04.2 LTS 5.4.0-1047-azure docker://20.10.6
ဒါဆိုရင်တော့ ကျွန်တော့်တို့ရဲ့ cluster မှာ node အားလုံးဟာ ready ဖြစ်နေပါပြီ။ အဲ့ဒီတော့ ဒီ k8s cluster ပေါ်မှာ pod တွေ deployment တွေ စ run လို့ရပါပြီ။ PART-II မှာပြန်တွေ့ကြမယ်နော်။ bye bye !!
Thanks for reading..