DEV Community

shah-angita for platform Engineers

Posted on

Installing Kubernetes on Bare Metal

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Installing Kubernetes on bare metal servers provides direct access to hardware resources, which can be beneficial for applications requiring high performance. This guide will walk you through the step-by-step process of installing Kubernetes on bare metal servers.

Prerequisites

Before you begin, ensure you have the following prerequisites in place:

  1. Dedicated Bare Metal Servers: You need physical machines with suitable hardware specifications. These servers will serve as the foundation for your Kubernetes infrastructure.
  2. Linux Distribution: Choose a Linux distribution that aligns with your project requirements. Popular choices include Ubuntu, CentOS, and Red Hat Enterprise Linux.
  3. Network Configuration: Ensure proper IP addresses, DNS settings, and network communication between your servers.
  4. Container Runtime: Kubernetes relies on a container runtime such as Docker.

Step-by-Step Installation

1. Set Up Physical Machines

  1. Install Operating System:
    • Install a lightweight Linux distribution on your bare metal servers. For example, you can use Ubuntu.
   # Update the package list
   sudo apt update

   # Upgrade the packages
   sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode
  1. Install Docker:
    • Docker is a critical component for containerization. Install Docker on your server.
   # Install Docker
   sudo apt install docker.io -y

   # Start Docker service
   sudo systemctl start docker

   # Enable Docker to start at boot
   sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode
  1. Disable Swap:
    • Kubernetes requires swap to be disabled on your servers. You can disable swap temporarily or permanently.
   # Disable swap temporarily
   sudo swapoff -a

   # To disable swap permanently, comment out the swap line in /etc/fstab
   sudo sed -i '/swap/ s/^$$.*$$$/#\1/g' /etc/fstab
Enter fullscreen mode Exit fullscreen mode

2. Install Kubernetes Tools

  1. Install kubeadm, kubelet, and kubectl:
    • These tools are essential for deploying and managing your Kubernetes cluster.
   # Add the Kubernetes repository
   sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

   # Add the Kubernetes source list
   sudo add-apt-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main"

   # Update the package list
   sudo apt update

   # Install kubeadm, kubelet, and kubectl
   sudo apt install kubeadm kubelet kubectl -y
Enter fullscreen mode Exit fullscreen mode
  1. Initialize the Kubernetes Cluster:
    • Use kubeadm to initialize the Kubernetes cluster on your master node.
   # Initialize the Kubernetes cluster
   sudo kubeadm init --pod-network-cidr 10.244.0.0/16
Enter fullscreen mode Exit fullscreen mode

This command initializes the Kubernetes control plane components on your master node. The --pod-network-cidr flag specifies the range of IP addresses to use for the pod network.

  1. Join Worker Nodes to the Cluster:
    • To add worker nodes to your cluster, use the join command provided by kubeadm init.
   # Copy the join command from the output of kubeadm init
   # Example:
   # kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>

   # Run the join command on each worker node
   sudo kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Enter fullscreen mode Exit fullscreen mode

3. Configure the Kubernetes Cluster

  1. Deploy a Pod Network:
    • A pod network is required for communication between pods. You can use a network plugin like Weave or Calico.
   # Deploy Weave as an example pod network
   kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Enter fullscreen mode Exit fullscreen mode
  1. Verify the Cluster:
    • Use kubectl to verify that your cluster is up and running.
   # Check the nodes in the cluster
   kubectl get nodes

   # Check the pods in the default namespace
   kubectl get pods -n default
Enter fullscreen mode Exit fullscreen mode

Platform Engineering Considerations

When deploying Kubernetes on bare metal, it is crucial to consider the platform engineering aspects. This includes ensuring that the underlying infrastructure is properly configured and maintained. Here are some key considerations:

  • Hardware Resources: Ensure that your bare metal servers have sufficient CPU, RAM, and storage capacity to accommodate your workloads.
  • Network Configuration: Proper network configuration is essential for communication between nodes in the cluster.
  • Security: Implement appropriate security measures to protect your cluster. This includes configuring firewalls, securing etcd, and using secure communication protocols.

Conclusion

Installing Kubernetes on bare metal servers involves several steps, including setting up physical machines, installing necessary tools, and configuring the cluster. By following these steps, you can create a robust Kubernetes cluster that provides direct access to hardware resources, which is beneficial for high-performance applications.

Additional Resources

For further exploration and mastery of Kubernetes, you can access extensive documentation and resources on the official Kubernetes website. This includes guides on best practices for cluster setup, managing Kubernetes components, and troubleshooting common issues.

Example Configuration Files

Here are some example configuration files that can be used during the installation process:

kubeadm Configuration File

apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
networking:
  podSubnet: "10.244.0.0/16"
Enter fullscreen mode Exit fullscreen mode

This configuration file specifies the pod network CIDR range.

kubectl Configuration File

apiVersion: v1
kind: Config
clusters:
- name: kubernetes
  cluster:
    server: "https://<control-plane-host>:<control-plane-port>"
users:
- name: kubernetes-admin
  user:
    client-certificate: /etc/kubernetes/pki/admin.conf
contexts:
- name: kubernetes-admin@kubernetes
  context:
    cluster: kubernetes
    user: kubernetes-admin
current-context: kubernetes-admin@kubernetes
Enter fullscreen mode Exit fullscreen mode

This configuration file sets up the kubectl client to connect to your Kubernetes cluster.

By carefully following these steps and considering the platform engineering aspects, you can successfully deploy and manage a Kubernetes cluster on bare metal servers.

Top comments (0)