k8s-二进制安装

发布时间 2023-03-29 15:41:41作者: du-z

安装前必读

本文档适用于k8s 1.17+
安装说明:

  1. 本文章将演示CentOS 7二进制方式安装高可用k8s 1.17+,相对于其他版本,二进制安装方式并无太大区别,只需要区分每个组件版本的对应关系即可。
  2. 生产环境中,建议使用小版本大于5的Kubernetes版本,比如1.19.5以后的才可用于生产环境。

基本环境配置

网段地址划分

主机信息,服务器IP地址不能设置成dhcp,要配置成静态IP;VIP(虚拟IP)不要和公司内网IP重复,首先去ping一下,不通才可用。VIP需要和主机在同一个局域网内!

192.168.75.10 master # 2C2G 40G
192.168.75.13 master1 # 2C2G 40G
192.168.75.14 master2 # 2C2G 40G
192.168.75.100 master-lb # VIP 虚IP不占用机器资源 # 如果不是高可用集群,该IP为Master的IP
192.168.75.11 node1 # 2C2G 40G
192.168.75.12 node2 # 2C2G 40G
K8s Service网段:10.96.0.0/12
K8s Pod网段:172.16.0.0/12

# 注意:宿主机网段、K8s Service网段、Pod网段不能重复

所有节点系统环境

[root@master ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

配置所有节点hosts文件

[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.75.10   master
192.168.75.11   node1
192.168.75.12   node2
192.168.75.13   master1
192.168.75.14   master2
192.168.75.100	master-lb

所有节点CentOS 7安装yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

所有节点安装必备工具

yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-p ersistent-data lvm2 git -y

关闭防火墙

所有节点关闭firewalld 、dnsmasq、selinux(CentOS7需要关闭NetworkManager,CentOS8不需要)

systemctl disable --now firewalld
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

关闭swap分区

所有节点关闭swap分区,fstab注释swap

1 swapoff -a && sysctl -w vm.swappiness=0
2 sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab

所有节点同步时间

下载ntpdate,所有节点同步时间

rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
yum install ntpdate -y

#所有节点同步时间。时间同步配置如下:

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' >/etc/timezone
ntpdate time2.aliyun.com

所有节点设置定时同步,加入到crontab

*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com

所有节点配置limit

ulimit -SHn 65535

vim /etc/security/limits.conf

# 末尾添加如下内容
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited

配置免密

参考SSH:集群中各机器免密登录远程主机