Now let's start building a real, albeit simple, Kubernetes cluster. We begin to give some definitions, useful to clarify ideas:
Kubeadm: A tool for quickly installing Kubernetes and setting up a secure cluster. You can use kubeadm to install both the control plane and the worker node components.
Kubectl: a command line tool for communicating with a Kubernetes API server. You can use kubectl to create, inspect, update, and delete Kubernetes objects.
Kubelet: an agent that runs on each node in the cluster. It makes sure that containers are running in a Pod. The kubelet takes a set of PodSpecs that are provided through various mechanisms and ensures that the containers described in those PodSpecs are running and healthy. The kubelet doesn’t manage containers which were not created by Kubernetes.
Preliminary steps
First, there are some minimum requirements to be met and steps to take before proceeding with the installation of Kubeadm:
- CentOS 7 (minimum supported version);
- at least 2 GB of RAM and 2 CPUs per machine;
- opening doors on the control plane (6443, 2379-2380, 10250-10252) and on the worker (10250, 30000-32767);
- uniqueness of MAC address and product_uuid for each node;
- complete connectivity between the cluster nodes;
- swap disabled on nodes.
Note
It's instructive to know which are the standard ports used by k8s and on which nodes (master, worker or, as we will see later, etcd) they must be opened. If you are using VMs instantiated thanks to OpenStack, it is not necessary to open these ports, because the machines communicate freely via their internal network.
Now let's do a little study for the last 3 points of the list. Let's start with MAC address and product_uuid of the cluster nodes, making sure they are different from each other
About complete connectivity, make sure the br_netfilter
module has been loaded
In order for a Linux node's iptables to correctly view bridged traffic (see here), verify that net.bridge.bridge-nf-call-iptables
is set to 1 in your sysctl
config
The swap is probably not active on our machines. We can see this by looking at the output of the command
The swap values should all be 0 bytes. If not, comment on the swap line of the /etc/fstab
file and reboot. In this way the swap is permanently deactivated.
Installation
Installing CRI
By default, Kubernetes uses the Container Runtime Interface (CRI) to interface with your chosen container runtime. So, you need to install a CRI into each node in the cluster, in order that Pods can run there. Common CRI with Kubernetes, on Linux, are: containerd, CRI-O and Docker. We will focus on the latter. First, therefore, install Docker on each of your nodes (install Docker on CentOS).
After installation, create the following .json
file in the given path to set up the Docker daemon
Finally, create the docker.service.d
folder and restart Docker
Installing kubeadm, kubelet and kubectl
At this point we are ready with the installation of Kubeadm
, Kubectl
and Kubelet
on all VM of the cluster (procedure valid, as well as for CentOS, also for RedHat and Fedora)