Kubeadm is a tool used to build Kubernetes (K8s) clusters. Kubeadm performs the actions necessary to get a minimum viable cluster up and running quickly. By design, it cares only about bootstrapping, not about provisioning machines (underlying worker and master nodes). Kubeadm also serves as a building block for higher-level and more tailored tooling.
Common use cases for Kubeadm include testing, creating baselines for more advanced K8s deployments, and providing new K8s users a simple starting point for cluster configuration. The specific features that make kubeadm useful in those applications are:
Quick minimum viable cluster creation
Kubeadm is designed to have all the components you need in one place in one cluster regardless of where you are running them.
Kubeadm can be used to set up a cluster anywhere whether it's your laptop, a Raspberry Pi, or public cloud infrastructure.
As Kubeadm creates clusters with minimal dependencies and quickly, it's an ideal candidate for creating disposable clusters on local machines for development and testing needs.
Building block for other tools
Kubeadm is not just a K8s installer. It also serves as a building block for other tools like Kubespray.
Kubeadm vs kOps vs Kubespray
Of course, kubeadm isn’t the only tool available to deploy a K8s cluster. kOps and Kubespray are two popular tools for the same general use case. However, each tool offers different functionality that makes them ideal for different applications. Before we dive into how to create the Kubeadm cluster, let's take a closer look at how it stacks up to the alternatives.
As we can see, Kubeadm is a more lightweight tool that doesn’t attempt to do everything kOps or Kubespray can. This is consistent with its focus on minimum viable clusters.
The Problems kubeadm Solves
With more robust tools available, why use kubeadm? In simple terms: because it reduces complexity and makes it easy to get a usable K8s cluster deployed.
Provisioning a Kubernetes cluster with other tools takes time, server resources, and expertise. Kubeadm is easy to get started with and lightweight enough to be used on local machines. As a result, many developers and testers prefer kubeadm for cases that require the fast deployment of a cluster with minimal resources.
How to Create a Kubernetes Cluster with kubeadm
Now that we know what kubeadm is, let’s walk through how to use it to create a Kubernetes cluster. In this example, we will create a 3 node cluster with 1 master node and 2 worker nodes.
1. Install Docker on All Three Nodes
Since kubeadm does not create infrastructure, as a prerequisite we need to provision 3 machines that will form the cluster.
2. Install kubeadm, kubelet, & kubectl on All Three Nodes
3. Initiate Cluster Setup on the Master Node
First, we’ll initialize the control plane node and specify a network range for the pods using CIDR notation: Note: This command prints very important information which will be used later by worker nodes to join the master and form a cluster. The output should look something like this:
Next, we’ll configure the kubeconfig file:
Run the kubectl version command on the Kube master node to verify it is up and running:
Next, we’ll check the nodes in the cluster with kubectl get nodes. At this point there should be only 1 node (the master node). Here’s an example of the expected output (don’t worry about the “NotReady” status, we’ll get to that soon!):
4. Add the Two Worker Nodes to the Cluster
With the master node created, we can add our worker nodes to the cluster.
Use kubeadm join command on both worker nodes:
After running join command on both the worker nodes, go to master nodes and run the kubectl get nodes command to verify that worker nodes have joined the cluster:
We can see the nodes have joined the cluster. Now let's take care of that NotReady status...
5. Set up Networking for the Cluster
Once the worker nodes are in the cluster, we need to configure the network settings.
Turn on iptables bridge calls on all three nodes:
Next, run this command on only the Kube master node:
Wait a few seconds run kubectl get nodes and all the nodes should have a “Ready” status:
That’s it! We now have a working K8s cluster!
Kubeadm Best Practices
Kubeadm is a great tool when used for its intended applications. Here are three best practices to keep in mind to ensure you’re using the right tool for the job and getting the most out of kubeadm.
Don’t use kubeadm for production clusters that require autoscaling: Generally, kubeadm should not be used for production clusters because it does not come with node autoscaling/cluster autoscaling functionality. This is because node autoscaling requires managing underlying infrastructure and hardware, which kubeadm leaves to other tools.
Take frequent backups of etcd: By default, kubeadm does not have a multi-etcd cluster for storing cluster state. Be sure to take regular backups of etcd in case a failure occurs.
Keep track of machines/nodes: Kubeadm can not turn machines off when they are not in use. As a result, you’ll need to use an external solution to track worker nodes and their resource utilization to cluster optimize cost and efficiency.
Continue Reading this Series