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 (complete guide https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-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);
- install Docker on the nodes (https://docs.docker.com/engine/install/centos/);
- complete connectivity between the cluster nodes and uniqueness of MAC address and product_uuid for each node;
- swap disabled on nodes.
Now let's do a little study for the last 2 points of the list.
Get the MAC address and product_uuid of the cluster nodes, making sure they are different from each other, using the commands
# Commands to get MAC address $ ip link $ ifconfig -a # Command to get the product_uuid $ sudo cat /sys/class/dmi/id/product_uuid
Make sure the br_netfilter module has been loaded. Use the command as verification
# Verify that the br_netfilter module is present $ lsmod | grep br_netfilter br_netfilter 22256 0 bridge 151336 1 br_netfilter # If not present, use $ sudo modprobe br_netfilter
At this point we add the following lines to our configuration sysctl file
$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF
The swap is probably not active on our machines. We can see this by looking at the output of the command
$ free -h total used free shared buff/cache available Mem: 3.7G 1.2G 223M 26M 2.3G 2.2G Swap: 0B 0B 0B
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
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)
$ cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg exclude=kubelet kubeadm kubectl EOF $ sudo setenforce 0 $ sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config $ sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes $ sudo systemctl enable --now kubelet