单机版K8S离线部署方法
近期由于项目交付实施,在工作之余整理了K8S部署方法,供大家交流学习!!!
1.1. 安装文件路径说明
#master和node节点安装文件存放路径(master1示例)
[root@master1 ~]# cd /k8s/
[root@master1 k8s]# pwd
/k8s
[root@master1 k8s]# tree -L 1
.
├── calico
├── docker
├── go1.17.7.linux-amd64.tar.gz
├── helm
├── k8s
├── kernel
└── kubernetes-1.23.1.tar.gz
#harbor安装文件存放路径
[root@harbor ~]# pwd
/root
[root@harbor ~]# tree -L 1
.
├── docker-compose
├── docker
├── harbor-offline-installer-v2.5.0.tgz
1.1.1. 所有节点时间同步
(已提供NTP时间服务器ntpserver-nj.gaccloud.com.cn)
NTP客户端配置
#安装ntp服务
[root@master1 k8s]# yum install -y ntp
#修改同步时间服务器
[root@master1 k8s]# vim /etc/ntp.conf
........./省略内容
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntpserver-nj.gaccloud.com.cn iburst #增加时间服务器配置
所有节点启动ntpd服务并设置开机自启
systemctl start ntpd && systemctl enable ntpd
所有节点服务器使用date命令查看时间是否同步
[root@master1 k8s]# ntpq -p
[root@master1 k8s]# date
1.1.2. 所有节点修改主机名
如下例:修改节点主机名,其它节点主机名仿照修改
修改主机名:hostnamectl set-hostname master1 && bash
原主机名:10.0.0.8 修改后主机名:harbor
原主机名:10.0.0.10 修改后主机名:master1
原主机名:10.0.0.11 修改后主机名:node1
原主机名:10.0.0.12 修改后主机名:node2
原主机名:10.0.0.13 修改后主机名:node3
原主机名:10.0.0.14 修改后主机名:node4
在各个节点以追加的方式添加host映射
cat << EOF >> /etc/hosts
10.0.0.10 master1
10.0.0.11 node1
10.0.0.12 node2
10.0.0.13 node3
10.0.0.14 node4 storage.com.cn
10.0.0.8 harbor
EOF
1.1.3. 防火墙、selinux、交换分区(所有节点)
# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
# 关闭 SELinux
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
# 开启远程访问
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config && systemctl restart sshd
# 禁用swap交换分区
sudo sed -i 's/.*swap.*/#&/' /etc/fstab && sudo swapoff -a && swapon -a && sudo sysctl -p
1.1.4. 升级内核版本(所有节点)
[root@master1 k8s]# cd /k8s/kernel
[root@master1 kernel]# ll
total 51352
-rw-r--r-- 1 root root 52583876 Mar 5 17:04 kernel-lt-5.4.192-1.el7.elrepo.x86_64.rpm
#rpm安装内核
[root@master1 kernel]# rpm -ivh kernel-lt-5.4.192-1.el7.elrepo.x86_64.rpm
#查看内核启动顺序
[root@master1 kernel]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
#通过名称设置为默认启动内核
[root@master1 kernel]# grub2-set-default "CentOS Linux (5.4.192-1.el7.elrepo.x86_64) 7 (Core)"
#查看内核启动项
[root@master1 kernel]# grub2-editenv list
#重启
[root@master1 kernel]# reboot
#查看内核版本
[root@master1 kernel]# uname -r
1.1.5. 部署nfs挂载
安装nfs服务(所有节点)
[root@master ~]# yum -y install nfs-utils rpcbind
[root@master ~]# systemctl start rpcbind.service
[root@master ~]# systemctl enable rpcbind.service
[root@master ~]# systemctl start nfs.service
[root@master ~]# systemctl enable nfs.service
nfs服务端配置
[root@node ~]# mkdir -p /nfs/data
[root@node ~]# chmod 777 -R /nfs
[root@node ~]# vim /etc/exports
/nfs 10.1.70.1/24(rw,sync,no_root_squash,no_all_squash)
#刷新生效