我们使用centos7的系统,内核升级到5.5.4,为什么使用升级后的内核,这是因为centos7.4的内核是3.10,在docker运行时,有内核bug,导致运行缓慢,出现一堆错误异常,可以查阅我另外一个博客文章。
一、安装前的准备工作
1、系统版本如下:
- Linux cka61.xulinpeng.cn 5.5.4-1.el7.elrepo.x86_64 #1 SMP Thu Feb 13 18:09:18 EST 2020 x86_64 x86_64 x86_64 GNU/Linux
- 系统最低配置为2核cpu,2GB内存,主机名称和MAC地址不能有冲突。
2、iptables不能使用nftables,nftables和kubeadm不兼容,将形成重复的防火墙规则,导致kube-proxy不能正常工作。
update-alternatives --set iptables /usr/sbin/iptables-legacy
3、检查端口没有没占用
控制节点
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
4、安装必须的工具包,可能会影响k8s正常工作,像nfs工具包不安装将导致pv挂载nfs时出现错误异常。
yum install vim net-tools nfs-utils yum-utils device-mapper-persistent-data lvm2 nfs-utils
5、关闭系统防火墙、selinux
[root@cka60 ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@cka60 ~]# setenforce 0
[root@cka60 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
6、关闭
swap,使用swap将会降低k8s性能,fstab中也要注释掉
[root@cka60 ~]# swapoff -a
# /etc/fstab
# Created by anaconda on Mon Feb 17 21:07:54 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=d9c958a2-8f63-47c0-b2e5-1a0478b4b129 / xfs defaults 0 0
UUID=