
A bare metal Kubernetes deployment involves setting up a Kubernetes cluster directly on physical servers, bypassing virtualization. This approach delivers exceptional performance and control, making it well-suited for high-efficiency workloads like AI/ML applications and high-performance computing tasks.
In this guide, you will learn the necessary steps to install and configure a Kubernetes cluster on bare metal infrastructure, detailing prerequisites, installation processes, networking options, and best practices for monitoring.
Advantages of Bare Metal Kubernetes Deployment
- Enhanced Performance: Direct hardware access minimizes latency and maximizes throughput.
- Resource Efficiency: Removing the hypervisor reduces overhead, thus allowing full utilization of hardware resources.
- Cost Savings: Optimized resource usage translates to better performance per dollar spent compared to virtualized setups.
- Flexibility: Control over hardware configurations enables tailored solutions for specific workload requirements.
Prerequisites
Ensure the following are in place before commencing the deployment:
-
Hardware Requirements:
- Master Node: At least 4 CPUs, 16 GB RAM, and 100 GB SSD.
- Worker Nodes: At least 2 CPUs, 8 GB RAM, and 100 GB SSD each.
-
Operating System: Ubuntu 24.04 LTS (or later) or CentOS 9 Stream installed on all nodes.
-
Network Configuration:
- Each node must have a static IP address.
- Proper DNS settings configured.
-
Access:
- SSH access with root or sudo privileges on all nodes.
Steps for Deployment
Step 1 – Prepare the Nodes
-
Update System Packages:Run the following command on all nodes:
sudo apt update && sudo apt upgrade -y
-
Set Hostnames and Hosts File:Assign unique hostnames and modify the
/etc/hosts
file on all nodes by adding each node’s IP and hostname.sudo hostnamectl set-hostname <node-name>
Update the
/etc/hosts
file accordingly. -
Disable Swap:Swap is not needed for Kubernetes. Disable it using:
sudo swapoff -asudo sed -i '/ swap / s/^/#/' /etc/fstab
-
Load Necessary Kernel Modules:Enable required networking modules:
sudo modprobe br_netfiltersudo tee /etc/modules-load.d/k8s.conf <<EOFbr_netfilterEOFsudo tee /etc/sysctl.d/k8s.conf <<EOFnet.bridge.bridge-nf-call-ip6tables=1net.bridge.bridge-nf-call-iptables=1EOFsudo sysctl --system
Step 2 – Install Container Runtime
Using containerd
as the container runtime:
sudo apt install -y containerdsudo mkdir -p /etc/containerdsudo containerd config default | sudo tee /etc/containerd/config.tomlsudo systemctl restart containerdsudo systemctl enable containerd
Step 3 – Install Kubernetes Components
Install Kubernetes components on all nodes:
sudo curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpgecho 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.listsudo apt-get updatesudo apt-get install -y kubelet kubeadm kubectlsudo apt-mark hold kubelet kubeadm kubectl
Step 4 – Initialize the Kubernetes Cluster (Master Node Only)
Initialize the cluster:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
After initialization, set up local kubeconfig:
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 5 – Open Kubernetes Ports and Deploy a Pod Network
Open necessary ports:
sudo ufw allow 6443/tcpsudo ufw allow 10250/tcpsudo ufw allow 2379:2380/tcp
Deploy Calico pod network:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Step 6 – Join Worker Nodes
To add worker nodes:
sudo kubeadm join <MASTER_NODE_IP>:6443 --token <TOKEN> --discovery-token-ca-cert-hash sha256:<HASH>
Step 7 – Deploy a Sample Application
For instance, deploy an nginx
server:
kubectl create deployment nginx --image=nginxkubectl expose deployment nginx --port=80 --type=NodePort
Access it using the worker node’s IP and the assigned NodePort.
Step 8 – Monitoring Kubernetes on Bare Metal
Consider using monitoring tools like Prometheus and Grafana for insights into cluster performance.
Conclusion
This guide detailed the process of deploying a Kubernetes cluster on bare metal hardware, emphasizing the benefits of performance and resource efficiency. Following these steps will help you effectively set up and manage your Kubernetes environment directly on physical machines.
Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.