In this post, we'll guide you through setting up a Kubernetes cluster by launching three virtual machines (VMs): one for the master node and two for the worker nodes.
Launching the Virtual Machines:
Prerequisites:
- Kubernetes requires each machine to have at least 2 CPUs and 2 GB of RAM for smooth operation.
First, we will launch the instances needed to set up our cluster.
While launching, it is important to note that a Kubernetes cluster requires machines with at least 2 CPUs and 2 GB of RAM.
We will launch three instances:
Master node
Node 1
Node 2
The master node will contain the control plane necessary for administering the cluster. Node 1 and Node 2 will be the worker nodes that join the cluster.
Initializing the master node.
First, we will initialize the master node. To do this, we will install utilities like kubectl, kubeadm, and kubelet on the node. You can install them by following the steps provided here: Install kubeadm.
You will also need a container runtime like containerd for smooth operation of your cluster. This can be installed by simply installing Docker.
sudo apt-get install docker.io
After installing the necessary packages, it's time to set up the control plane.
We will simply run:
kubeadm init
This will initialize the control plane.
After initialization, it will output a token and hash that the worker nodes will use to join the cluster.
Also, it is necessary to export your configuration so that kubectl can access the cluster information.
This is done by using the command:
export KUBECONFIG=/etc/kubernetes/admin.conf
Setting up the worker nodes
Here, we will set up the worker nodes and make them join the cluster.
As with the master node, we will install kubelet, kubeadm, and kubectl, along with a container runtime, on the worker nodes as well.
After installation, we will run the command provided by the master node to join the cluster:
kubadm join <master-node ip> --token <token> --discovery-token-ca-cert-hash <hash>
This will help the node join the cluster.
After joining, we can check the status on the master node by running:
kubectl get nodes
It will display the status and list all the nodes in the cluster.
Thus, your cluster is now ready. You can launch pods on these nodes to run your containers.