Deploy a K8S cluster in 180 seconds through Sealos

Deploy a K8S cluster in 180 seconds through Sealos

1. Host preparation

1.1 Host operating system description

Serial number Operating system and version Remarks
1 CentOS7u9

1.2 Host hardware configuration instructions

The k8s cluster CPU and memory are at least 2 CPUs and 2G memory respectively, and the hard disk is recommended to be 100G +

Requirements CPU Memory Hard Disk Role Hostname
Value 8C 8G 1024GB master k8s-master01
Value 8C 8G 1024GB master k8s-master02
Value 8C 8G 1024GB master k8s-master03
value 8C 16G 1024GB worker(node) k8s-worker01
Value 8C 16G 1024GB worker(node) k8s -worker02

1.3 Host Configuration

1.3.1 Host name configuration

Since 5 hosts are used to complete the kubernetes cluster deployment this time, 3 of them are master nodes, and their names are k8s-master01, k8s-master02, and k8s-master03; 2 of them are worker nodes, and their names are: k8s-worker01 and k8s. -worker02

master node
# hostnamectl set-hostname k8s-master01
master node
# hostnamectl set-hostname k8s-master02
master node
# hostnamectl set-hostname k8s-master03
worker01 node
# hostnamectl set-hostname k8s-worker01
worker02 node
# hostnamectl set-hostname k8s-worker02

1.3.2 Host IP address configuration

The IP address of the k8s-master01 node is: 192.168.10.140/24
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.140"
PREFIX="24"
GATEWAY="192.168.10.2"
DNS1="119.29.29.29"
The IP address of the k8s-master02 node is: 192.168.10.141/24
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.141"
PREFIX="24"
GATEWAY="192.168.10.2"
DNS1="119.29.29.29"
The IP address of the k8s-master03 node is: 192.168.10.142/24
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.142"
PREFIX="24"
GATEWAY="192.168.10.2"
DNS1="119.29.29.29"
The IP address of k8s-worker01 node is: 192.168.10.143/24
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.143"
PREFIX="24"
GATEWAY="192.168.10.2"
DNS1="119.29.29.29"
The IP address of the k8s-worker02 node is: 192.168.10.144/24
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.144"
PREFIX="24"
GATEWAY="192.168.10.2"
DNS1="119.29.29.29"

1.3.3 Host name and IP address resolution

All cluster hosts need to be configured.

# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.140 k8s-master01
192.168.10.141 k8s-master02
192.168.10.142 k8s-master03
192.168.10.143 k8s-worker01
192.168.10.144 k8s-worker02

1.3.4 Firewall Configuration

All hosts require operation.

Close existing firewall firewalld
# systemctl disable firewalld
# systemctl stop firewalld
# firewall-cmd --state
not running

1.3.5 SELINUX configuration

All hosts require operation. Modifying the SELinux configuration requires restarting the operating system.

# sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# sestatus

1.3.6 Time synchronization configuration

All hosts require operation. The minimal installation system requires the installation of ntpdate software.

# crontab -l
0 */1 * * * /usr/sbin/ntpdate time1.aliyun.com

1.3.7 Upgrade operating system kernel

All hosts require operation.

Import elrepo gpg key
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
Install elrepo YUM source repository
# yum -y install https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
Install the kernel-ml version, ml is the latest stable version, lt is the long-term maintenance version
# yum --enablerepo="elrepo-kernel" -y install kernel-lt.x86_64
Set grub2 default boot to 0
# grub2-set-default 0
Regenerate grub2 boot file
# grub2-mkconfig -o /boot/grub2/grub.cfg
After the update, you need to restart and use the upgraded kernel to take effect.
# reboot
After restarting, you need to verify whether the kernel is updated to the corresponding version.
# uname -r

1.3.8 Close SWAP partition

After the modification is completed, the operating system needs to be restarted. If it does not restart, it can be temporarily shut down. The command is swapoff -a.

Closing the swap partition permanently requires restarting the operating system.
# cat /etc/fstab
...

# /dev/mapper/centos-swap swap swap defaults 0 0

Add # at the beginning of the previous line

2. Sealos software preparation

[root@k8s-master01 ~]# wget https://github.com/labring/sealos/releases/download/v4.3.0/sealos_4.3.0_linux_amd64.rpm
[root@k8s-master01 ~]# yum -y install sealos_4.3.0_linux_amd64.rpm

3. Deploy K8S cluster using Sealos

[root@k8s-master01 ~]# vim sealos-install-k8s.sh
[root@k8s-master01 ~]# cat sealos-install-k8s.sh
sealos run labring/kubernetes:v1.26.5 labring/helm:v3.12.0 labring/calico:v3.24.6 \
--masters 192.168.10.140,192.168.10.141,192.168.10.142 \
--nodes 192.168.10.143,192.168.10.144 -p centos
[root@k8s-master01 ~]# sh sealos-install-k8s.sh