DevOps Classroomnotes 07/Sep/2023

Installing K8s using Kube-adm

Steps:

  • Create 3 vms/ec2 instances as discussed in the class (Azure/AWS)
  • Install Docker on all the nodes
curl -fsSL https://get.docker.com -o install-docker.sh
sh install-docker.sh
  • To install CRI-dockerd Refer Here and get the latest releases. Below steps are specific to ubuntu 22.04
wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.4/cri-dockerd_0.3.4.3-0.ubuntu-jammy_amd64.deb
sudo dpkg -i cri-dockerd_0.3.4.3-0.ubuntu-jammy_amd64.deb


* Execute the above step on all 3 nodes
* Install kubeadm, kubectl and kubelet on 3 nodes Refer Here
* Execute the following on 3 nodes

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | 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


* Now Lets create a k8s cluster using kubeadm Refer Here
* Execute the following on master node
* Lets initialize the cluster using the following command as a root user

kubeadm init --pod-network-cidr "10.244.0.0/16" --cri-socket "unix:///var/run/cri-dockerd.sock"
  • Kubeadm responds with the following info
To start using your cluster, you need to run the following 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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should 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/

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

kubeadm join 172.31.7.94:6443 --token z5wbh4.628cq6vbtcgkekz5 \
        --discovery-token-ca-cert-hash sha256:26648765455a9ca4e151f89889c9cf6a4902f0e1d17516a583b0ac7d92cefe0f
  • On the master node to run kubectl as regular user execute the following
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Now as a regular user execute kubectl get nodes
  • Now as a root user in node 1 and node 2 execute the join command
kubeadm join 172.31.7.94:6443 --token z5wbh4.628cq6vbtcgkekz5 \
        --discovery-token-ca-cert-hash sha256:26648765455a9ca4e151f89889c9cf6a4902f0e1d17516a583b0ac7d92cefe0f \
        --cri-socket "unix:///var/run/cri-dockerd.sock"
  • Now execute kubectl get nodes from master node
  • Now kuberentes needs CNI Plugin so that pod-network is enabled. Till this is done the DNS doesnot work, services donot work so nodes are shown as NotReady.
  • We can choose among wide range of CNI Plugins, For this lets use flannel. Execute the following on master node kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
  • Now execute kubectl get nodes -w and wait for all the nodes to get to ready state
  • Kubectl cheatsheet Refer Here
  • Lets setup autocomplete for kubectl
  • note: use tabs

kubectl: kubernetes control

  • This is a command line tool to communicate with k8s api server.
  • Inside k8s we have a Certificate Authority and keys available which are used to secure all k8s communications.
  • The kubeconfig file contians the certificate data to be connected securely as admin into k8s (This is based on installations which we have done so far)

Exercise

  • Setup a two node kubeadm cluster
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency
Exit mobile version
%%footer%%