0%

K8s 集群搭建系列(一) Centos 7 准备

引言

心血来潮,打算重整一下我的 K8s 环境,反正也是要重新搭建,不如趁着这次机会开一专题记录一下,从零开始搭建。这一篇呢,我们主要讲解 Centos 7 的准备(本来想用 Centos 8 无奈已经被官方抛弃了 【详情】),好了直接进入主题。

环境与版本

  • Mac(macOS 10.14.6 )宿主机
  • 虚拟机 VMware Fusion
  • CentOS-7-x86_64-Minimal-1908.iso

    开始

    网络设置

    网络这里选择【与我的 Mac 共享】,之所以采用 NAT 模式而不是桥接模式是因为,如果在公司使用的话,ip 这里会是个问题,因为每个虚拟机都需要一个桥接 ip

磁盘这里我这里用了10 GiB,没办法,电脑磁盘太小,而且这个集群只跑 demo 用。
CPU 跟内存这一块需要稍微注意一下:

我这里分配了所需资源的最小值,当然这个可以动态调整,所以关系不大。记住这里分配的动态 ip、网关等,我们需要把它设置成静态的。

静态 ip(当然也可以进入系统里设置,如果你不嫌麻烦的话)

这里你可以 ping 一下这个 ip,看宿主机是否可以连接到你的虚拟机内部

分区

占用空间较大的就是 / 以及 /var,如果你的磁盘足够大,其他分区也可以调整的大一些。

安装中。。。。

必要软件安装

1
2
3
4
# 更新 yum
[root@localhost ~]# yum update -y
# 安装 vim 以及 ifconfig
[root@localhost ~]# yum install -y vim net-tools.x86_64

免密登录

  • 密钥生成
1
Tubetrue01:~:% ssh-keygen -o -a 100 -t ed25519 -f "The path where you store" -C "Your Email"
  • 上传至你的虚拟机
1
Tubetrue01:~:% ssh-copy-id -i "The path where you store"/id_ed25519.pub root@server 
  • sshd 设置
1
2
3
4
5
6
7
# 编辑配置文件
[root@localhost ~]# vim /etc/ssh/sshd_config
# 修改值
PubkeyAuthentication yes
PasswordAuthentication no
# 重启 sshd
[root@localhost ~]# systemctl restart sshd

内核升级(非必须)

我们可以把内核升级一下,然后开启 BBR 算法。

  • 内核安装
1
2
3
4
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@localhost ~]# rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
[root@localhost ~]# yum --enablerepo=elrepo-kernel install -y kernel-ml
[root@localhost ~]# grub2-set-default 0
  • 关闭开机读秒
1
2
3
4
5
6
7
8
9
10
11
# 编辑配置文件
[root@localhost ~]# vim /boot/grub2/grub.cfg

# 将超时时间设置为 0
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
# set timeout=5
set timeout = 0

# 重启
[root@localhost ~]# reboot
  • 内核查看
1
2
[root@localhost ~]# uname -r
5.10.2-1.el7.elrepo.x86_64
  • 开启 BBR
1
2
3
4
5
6
[root@localhost ~]# echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
[root@localhost ~]# echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
[root@localhost ~]# sysctl -p
# 查看是否开启
[root@localhost ~]# lsmod | grep bbr
tcp_bbr 20480 1
  • 设置资源配置
1
2
3
4
5
6
7
# 编辑文件
[root@localhost ~]# vim /etc/security/limits.conf
# 尾部添加
* soft nofile 65535
* hard nofile 65535
# 运行指令
[root@localhost ~]# ulimit -n 65535

尾声

好了,系统已经准备完毕,我们马上进入下一步 【Docker 安装】