kubernetes cluster setup 01 environment preparation

Posted by essexboy on Sun, 19 Sep 2021 14:17:56 +0200

Environmental Science:

Ubuntu 20.04.2 LTS \n \l

Kubedm is recommended for cluster construction in production environment,

The starting point of kubedm tool is very simple, which is to deploy a Kubernetes cluster available for production as easily as possible. In fact, it is really simple. You only need two commands:

# Create a Master node
$ kubeadm init

# Add a Node to the current cluster
$ kubeadm join <Master Nodal IP And ports >

1 - Environmental preparation:

My three virtual machine servers

172.30.10.175   master
172.30.10.25     node1
172.30.10.164     node2

1: Set the mutual resolution of system hostname and Host file

View host name: hostname

Modify host name: vim /etc/hostname

Restart the system: reboot

Execute the above commands on the three virtual machines. The host names are: master,node1,node2



add to host Resolution:

edit etc/hosts file

cat <<EOF>> /etc/hosts
172.30.10.175   master
172.30.10.25     node1
172.30.10.164     node2
EOF
 Execute the above on three servers respectively

verification
 Find any server, ping The following hostname tests
ping node1
ping node2

2: Time synchronization

kubernets requires that the time nodes in the cluster must be accurate and consistent;

3: Disable iptables and firewalld services

kubernets and docker will generate a large number of iptables rules during operation (some forwarding and routing will be realized). In order not to confuse the system rules with them, close the system rules directly;

Turn off the firewall:
sudo ufw status View current firewall status
sudo ufw enable Turn on the firewall
sudo ufw disable Turn off firewall

close iptables Services:
apt-get remove iptables

4: Close selinux

selinux is a security service under linux system. If it is not closed, various strange problems will occur when installing the cluster;

edit/etc/selinux/config Documents,
modify SELINUXD The value of is disabled

Note that the server needs to be restarted after modification
 Restart: reboot

my ubuntu 20 Can't find this file. Who knows how to close it


see selinux On or off:
getenforce

However, you will be prompted that there is no such tool. First, install this tool:
apt install selinux-utils

Then I install it and then getenforce: 
root@master:/etc/selinux# getenforce
Disabled

It is already closed;

5: Disable swap partition

swap partition refers to virtual memory partition, which is used to convert disk space into virtual memory after physical memory is used up;

Enabling the swap device will have a very negative impact on the performance of the system. Therefore, kubernetes requires that each node disable the swap device. However, if the swap partition cannot be closed for some reasons, it needs to be described through explicit parameters during cluster installation;

Disable swap Partition:
vim /etc/fstab
 Comment out the last line swap

Then restart:
reboot

then free -m 
Can see swap Your space is 0

6: Adjusting kernel parameters in linux

modify linux Add bridge filtering and address forwarding functions


1: Add a file to edit as follows:
vim /etc/sysctl.d/kubernetes.conf
 Add the following configuration:

net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1

After modification, you need to reload the configuration:
sysctl -p /etc/sysctl.d/kubernetes.conf
 perhaps
sysctl -p


2: Load bridge filter module:
modprobe br_netfilter

Check whether the load is successful:
lsmod |grep br_netfilter

7: Configure ipvs function

In kubernetes, there are two proxy models for service (exposed service port interface, load balancing and reverse proxy). One is based on iptables and the other is based on ipvs,

Compared with the two, the performance of ipvs is obviously higher, but if you want to use it, you need to manually load the ipvs module;

apt install ipvsadm ipset -y
# As the forwarding mechanism of Kube proxy, ipvs enables ipvs module support
modprobe ip_vs && modprobe ip_vs_rr && modprobe ip_vs_wrr && modprobe ip_vs_sh
# Boot enabled ipvs
cat <<EOF >> /etc/modules
ip_vs_rr
ip_vs_wrr
ip_vs_sh
ip_vs
EOF



Check whether the installation is successful
lsmod | grep -e ip_vs -e nf_conntrack_ipv4

After the above installation is completed, it is best to restart the next three servers;

reference resources:

Kubedm deployment 1.17.3 [based on Ubuntu 18.04] - cloud native way - blog Park

Topics: Operation & Maintenance Docker Kubernetes