Voiced by Amazon Polly |
Overview
Kubeadm is a tool that performs the necessary actions to set up a minimal viable cluster and run quickly. Change is an integral part of the Kubernetes lifecycle. Some of its use cases include testing, creating baselines for advanced Kubernetes deployments, and providing beginners a starting point to configure the cluster properly.
Features of Kubeadm:
- Easy to create a minimal viable cluster: Kubeadm is designed so that all the components are present in one place in a cluster.
- Easily provision volumes from cross-namespace snapshot: This feature allows the end user to provision a volume from volume snapshot, which greatly benefits applications and users, For example, enabling administrators to snapshot a database before any critical operation.
- It can set up a k8s cluster anywhere on a laptop or public cloud.
These are some of the features to consider. Now, let’s create a kubeadm cluster on the Azure Cloud platform.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Steps to create a Kubeadm cluster on the Azure Cloud platform
Step 1 – Create your cloud infrastructure, including one master VM and two worker nodes.
- Go to the Azure portal (portal.azure.com) and search for virtual machines in the search bar.
- Select the virtual machine and create an Azure Virtual machine for the master node as per the below configuration.
a. The required configurations are: Ubuntu 20.04 LTS image and atleast 4 GB of RAM each instance should have. (Here, we have selected 8 GB RAM and 2 vcpus)
3. Set the username, generate a new keypair, and open the inbound port 22 on your VM.
4. Click on Review + Create. After successful validation, click on Create.
5. Don’t forget to download your keypair.
6. Once your master VM is created, follow the steps from 2 to 4 and create the other two worker nodes with the same configuration.
Step 2 – Run these commands on all the nodes.
- Take ssh of all the nodes (using Putty, mobaxterm, or any other tool).
- Run the below commands on all of your nodes.
1 2 3 4 5 6 |
~$ sudo su ~$ 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 ~$ sudo apt update -y ~$ sudo apt -y install vim git curl wget kubelet=1.26.0-00 kubeadm=1.26.0-00 kubectl=1.26.0-00 ~$ sudo apt-mark hold kubelet kubeadm kubectl |
3. Load the br_netfilter module to facilitate the virtual Extensible LAN (VxLAN) traffic for communication between pods across the cluster.
1 2 3 4 5 6 7 8 |
~$ sudo modprobe overlay ~$ sudo modprobe br_netfilter ~$ 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 |
4. Setup containers, a container runtime that manages the lifecycle of the containers on a host, i.e., a daemon process that creates, starts, stops, and terminates the containers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
~$ cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf >overlay >br_netfilter >EOF ~$ sudo modprobe overlay ~$ sudo modprobe br_netfilter # Setup required sysctl params, these persist across reboots. ~$ cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf >net.bridge.bridge-nf-call-iptables = 1 >net.ipv4.ip_forward = 1 >net.bridge.bridge-nf-call-ip6tables = 1 >EOF # Apply sysctl params without reboot ~$ sudo sysctl --system #Install and configure containerd ~$ 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 -y ~$ sudo apt install -y containerd.io ~$ sudo mkdir -p /etc/containerd ~$ containerd config default | sudo tee /etc/containerd/config.toml #Start containerd ~$ sudo systemctl restart containerd ~$ sudo systemctl enable containerd |
Above commands will install containerd version 2.
5. Now, pull the image for Kubernetes 1.26 version.
1 |
~$ sudo kubeadm config images pull --image-repository=registry.k8s.io --cri-socket unix:///run/containerd/containerd.sock --kubernetes-version v1.26.0 |
Step 3 – Run the kubeadm init on the control plane node (master node)
- In this command, the pod network CIDR depends on the container network interface, which we will be downloading later on and using flannel. The control-plane-endpoint parameter will be the public IP of the master node.
1 |
~$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --upload-certs --kubernetes-version=v1.26.0 --control-plane-endpoint=74.220.27.73 --cri-socket unix:///run/containerd/containerd.sock |
The above command will give the following output:
Copy the join command from the output to join the worker nodes.
Note: If you receive any such error which says,
“Initial timeout of 40 seconds passed. Either your kubelet is not running properly, or the kubelet is unhealthy due to any of the misconfiguration in the node (cgroups disabled required)”
Then run these three below commands:
2. If everything works fine, then export KUBECONFIG and install CNI Flannel.
1 2 3 4 5 |
~$ 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 |
Step 4 – Run the kubeadm join command on all the worker nodes
- Run the kubeadm join command on both the worker nodes, which you copied earlier in the previous step.
2. After running the above command, run ‘kubectl get nodes’ on the master node to check the joined worker nodes.
Once the cluster is up and running, you can create your pods running your application inside the cluster.
Conclusion
In this blog, we installed Kubernetes on the Kubeadm cluster. As a DevOps Engineer, we should understand the basic components of Kubernetes. While working with managed services, we often miss learning the basic building blocks of Kubernetes. This setup of the Kubeadm cluster is good for learning and playing around with Kubernetes. Having the whole cluster setup in virtual machines lets you learn all the cluster components configs and troubleshoot the cluster if there is any component failure.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
Drop a query if you have any questions regarding Terraform, Kubernetes, Kubeadm and I will get back to you quickly.
To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.
FAQs
1. For how long the token is valid?
ANS: – Kubeadm init creates an initial token for 24 hrs TTL. The commands allow you to manage a token and create new ones:
1 |
Kubeadm token create [token] --ttl duration |
2. How to use Kubeadm certs certificate-key?
ANS: – The command can generate a new control-plane certificate key which can be passed as –certificate-key to Kubeadm init, and Kubeadm join to enable the automatic copy of certificates when joining additional control plane nodes.
3. How to upgrade the Kubeadm version?
ANS: – The command checks which versions are available to upgrade to and verify whether your current cluster is upgradeable.
1 |
Kubeadm upgrade plan [version] [flags] |
WRITTEN BY Harshita Gupta
Shreyas Gupta
May 10, 2023
Insightful
Prashant Khosre
May 10, 2023
This is very useful information.
Click to Comment