Installing Prerequisites for Kubernetes Cluster Installation
Getting Started
If you want to install a Kubernetes cluster, you need to meet the following prerequisites before you start your actual work. Below requirements are taken from the official website:
One or more machines running one of:
Ubuntu 16.04+
Debian 9+
CentOS 7
Red Hat Enterprise Linux (RHEL) 7
Fedora 25+
HypriotOS v1.0.1+
Flatcar Container Linux (tested with 2512.3.0)
2 GB or more of RAM per machine (any less will leave little room for your apps).
2 CPUs or more.
Full network connectivity between all machines in the cluster (public or private network is fine).
Unique hostname, MAC address, and product_uuid for every node. See here for more details.
Certain ports are open on your machines. See here for more details.
Swap disabled. You MUST disable swap in order for the kubelet to work properly.
I will try to cover CentOS 7 and Ubuntu 18.04 / 20.04 under that post. So let's write an Ansible role to cover the prerequisites.
Kubernetes cluster installation and configuration require certain prerequisites to be done in advance. I divided those prerequisites into 3 categories in my role:
Swap
SELinux
Firewall
I prefer to keep the above specific tasks into their own yaml
files and import them in the role's main file. You can find the Ansible role here.
Disabling Swap
If you fail to disable swap space before your Kubernetes cluster setup, it will throw an ugly error and will ask you to disable it. Disabling swap space looks straightforward but if you want to automate it, it can be a tricky task because you can have either a swap volume or a file. There is also another risk that if you remove the swap logical volume and if your GRUB configuration expects for it, your server will not boot up after the first reboot. That's why I decided to only disable swap and uncomment it in the /etc/fstab
file and let the administrators handle it properly if they want to reclaim the swap space.
I am disabling swap space in a separate playbook as below:
Please pay attention to the swapfile_path
variable in the vars/main.yml
file and change it accordingly.
Please note that swap needs to be disabled on both control and worker nodes
Disable SELinux
I call the title of the section "disable" but I prefer to put SELinux into permissive mode. Since SELinux status is a variable (either permissive
or disabled
), I kept it in vars/main.yml
file as below:
Ubuntu servers do not come with SELinux by default, so I decided to touch SELinux configuration only if its configuration file exists. The playbook to handle SELinux tasks will be like below:
Please note that. SELinux needs to be disabled on both control and worker nodes.
Enable Firewall Rules for Control and Worker Nodes
There are some ports to be enabled on both the control plane and worker nodes. The list of ports can be also found here.
Protocol | Direction | Port Range | Purpose | Used By |
TCP | Inbound | 6443* | Kubernetes API server | All |
TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
TCP | Inbound | 10250 | kubelet API | Self, Control plane |
TCP | Inbound | 10251 | kube-scheduler | Self |
TCP | Inbound | 10252 | kube-controller-manager | Self |
Worker node(s)
Protocol | Direction | Port Range | Purpose | Used By |
TCP | Inbound | 10250 | kubelet API | Self, Control plane |
TCP | Inbound | 30000-32767 | NodePort Services† | All |
CentOS servers by default use firewalld
and Ubuntu servers use ufw
to manage firewall rules. I will not make any exception here and assume you are using the default services. Then the playbook will look like below:
Putting things together
Now we are ready to put things together.
Please note that the control plane nodes should be under master
group in the inventory file and worker nodes should be in node
group.
What we need to do is relatively simple now. We just need to include our tasks in the main playbook like below:
Now we are ready to install the container runtime interface.
Last updated