Installing Prerequisites for Kubernetes Cluster Installation
Last updated
Was this helpful?
Last updated
Was this helpful?
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 :
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 for more details.
Certain ports are open on your machines. See 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
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:
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:
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
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:
Now we are ready to put things together.
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.
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 .
There are some ports to be enabled on both the control plane and worker nodes. The list of ports can be also found .