While you can run Kubernetes in many different environments, bare metal deployment is becoming increasingly popular. Running Kubernetes on bare metal comes with several advantages, including better security, less network complexity, lower costs, and complete control over your entire architecture. If you want to experience these benefits, simply follow our quick guide below.
Here we're going to outline how to install Kubernetes 1.16 on a bare-metal machine Ubuntu 18.04. Let's get started.
Prerequisites
Before you dive right in, you'll need to make sure you have the following:
Two or more Linux servers with Ubuntu 18.04.
Access to a user account with sudo or root privileges for each system.
The apt package manager.
Terminal window/command-line.
Step 1: Installation
The first thing we need to do is install Docker and any related packages on all Kubernetes nodes.
- First, we install Kubernetes by using the following command: sudo apt-get update
- Next, we install Docker with the command: sudo apt-get install docker.io
- To set Docker to launch at boot, we use this command: sudo systemctl enable docker
- To add Kubernetes software repositories, we use:
$ sudo apt-get update \ && sudo apt-get install -y apt-transport-https \ && curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
If you get an error telling you that curl is not installed, you can install it with: sudo apt-get install curl
Lastly, to perform package updates, we use:
$ echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" \ | sudo tee -a /etc/apt/sources.list.d/kubernetes.list \ && sudo apt-get update
Repeat this process on each server node.
Step 2: Kubernetes Installation Tools
Next, we want to install kubelet, kubeadm, and Kubernetes-cni. Kubelet is the work package or primary node agent that runs on each node. It's responsible for all communications between the Kubernetes control plane and the nodes where the workload runs. Kubeadm (Kubernetes Admin) is a tool used to perform actions necessary to get a minimum viable cluster up and running. And Kubernetes-cni offers networking components not directly built into Kubernetes.
To install these three tools we use the following command:
$ sudo apt-get update \
&& sudo apt-get install -yq \
kubelet \
kubeadm \
kubernetes-cni
Step 3: Deployment
Now we need to disable swap memory. Having swap enabled can cause performance issues and lead to unpredictable results, so to disable it, we use: sudo swapoff –a
Do this for each server.
Next, we need to assign a unique hostname for each server node. When you've decided on your master node, you can assign its status using: sudo hostnamectl set-hostname master-node
For worker nodes, use: sudo hostnamectl set-hostname worker01
Of course, each worker node should be given a different name.
Step 4: Create a Directory for the Cluster
One the master node, use the following command: sudo kubeadm init --pod-network-cidr=10.244.0.0/16
You should see a kubeadm join message once this command finishes. Please make a note of this because it's crucial in the next section.
Now to create a directory for our cluster, we use:
kubernetes-master:~$ mkdir -p $HOME/.kube
kubernetes-master:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
kubernetes-master:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 5: Join Worker Nodes to the Cluster
You can connect each worker node to the cluster using the kubeadm join message you copied from the last section. So, for example, you can switch to worker01, enter the kubeadm join command, and then repeat for each worker node.
Once you've completed this step, you can check the status of the nodes by switching to the master server and typing: kubectl get nodes
Step 6: Connect Interrelated Components Through a Pod Network
To allow communication between different nodes in your cluster, you'll want to deploy a pod network. To do this, choose from one of the options listed here and run: kubectl apply -f [podnetwork].yaml.
And that's a wrap! We hope you found our quick guide to installing Kubernetes on bare metal helpful!