Simplifying Kubernetes Cluster Setup with Kubeadm Installation Guide π
π Introduction:
In the world of container orchestration, Kubernetes has emerged as the de facto standard. It provides a powerful platform for managing containerized applications, but setting up a Kubernetes cluster can be a daunting task. That's where Kubeadm comes to the rescue. In this guide, we'll walk you through the process of setting up a Kubernetes cluster using Kubeadm on Ubuntu.
π Prerequisites β
Before we dive into the installation process, let's make sure we have everything we need:
Ubuntu OS (Xenial or later): We'll use Ubuntu as our operating system.
sudo privileges: You need administrative access to the servers.
Internet access: To download necessary packages.
t2.medium instance type or higher: This guide assumes you have access to suitable hardware.
Both Master & Worker Node: For a fully functional cluster.
π Installation Steps π οΈ
Update and Install Docker π³
Run the following commands on both the master and worker nodes to prepare them for Kubeadm:
sudo su apt update -y apt install docker.io -y systemctl start docker systemctl enable docker
Kubernetes relies on Docker containers, so it's essential to have Docker installed and running on all nodes.
Add Kubernetes Repository and Install Kubeadm π¦
To add the Kubernetes repository and install Kubeadm, Kubectl, and Kubelet components, execute:
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' > /etc/apt/sources.list.d/kubernetes.list apt update -y apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Initialize the Kubernetes Master Node π
Run this command to initialize the Kubernetes control plane on the master node:
sudo su kubeadm init
Set Up Local Kubeconfig π
To interact with the Kubernetes cluster from your local machine, create the Kubeconfig file:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Apply Weave Network Plugin π
Use this command to apply the Weave network plugin, which ensures pod-to-pod communication:
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
Generate Token for Worker Nodes π€
Generate a token for worker nodes to join the cluster:
kubeadm token create --print-join-command
Expose Port 6443 for Worker Node Connectivity π
- Ensure that port 6443 is accessible from your worker nodes to the master node. This is essential for the worker nodes to communicate with the control plane.
π Worker Node Setup ποΈ
Reset Kubeadm and Join Worker Node π
On the worker node, execute the following commands:
sudo su kubeadm reset pre-flight checks
Then, paste the join command you obtained from the master node during token creation and append
--v=5
for verbose output:kubeadm join <master-node-ip>:6443 --token <token> --discovery-token-ca-cert-hash <hash> --v=5
Verification βοΈ
On the master node, run:
kubectl get nodes
This should display both the master and worker nodes as part of your Kubernetes cluster.
π Optional Steps π§
Labeling Nodes π·οΈ: If you want to label your worker nodes for specific roles, you can use the following command:
kubectl label node <node-name> node-role.kubernetes.io/worker=worker
Testing a Demo Pod π: To verify your cluster's functionality, you can deploy a demo pod:
kubectl run nginx --image=nginx --port=80 kubectl expose pod nginx --port=80 --type=NodePort
Enable the port range 30000-32767 for the node-port on worker node
Now, type the below command to know the node-port for the pod
kubectl get svc
Node copy the public-ip of workernode: nodeport in the browser to get the nginx output
This will run a simple pod:
πConclusion:
Congratulations! You've successfully set up a Kubernetes cluster using Kubeadm on Ubuntu. This provides you with a powerful platform for deploying and managing containerized applications in a scalable and efficient manner. π
π Checkout GitHub Repository for projects:
π github.com/sumanprasad007