centos 7 kubernetes 集群部署
主机(虚拟机)信息:
[root@k8s-master ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
节点名称 | IP |
---|---|
k8s-master | 192.168.1.86 |
k8s-node1 | 192.168.1.87 |
注:
1、k8s版本可自行选择,此处以 1.16.2 为例。
2、除集群初始化仅master执行以外,其余部署步骤在所有节点上执行。
1. centos 7 配置
关闭防火墙、关闭selinux、更新源
#防火墙
systemctl disable firewalld.service
#关闭Selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
## 或者
/etc/selinux/config
#将其中的 SELINUX=*处修改为如下
SELINUX=disabled
#重启服务器
#运行命令getenforce 确保 selinux 为disable
#安装wget
yum install -y wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#更新 源
yum upgrade
2. host配置
cat /etc/hosts
#k8s nodes
192.169.1.86 k8s-master
192.168.1.87 k8s-node1
cat /etc/hostname
## 节点名称 k8s-master或k8s-node1
# 重启
reboot
3. 创建/etc/sysctl.d/k8s.conf文件
#修改内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#执行sysctl -p /etc/sysctl.d/k8s.conf生效(sysctl --system)
sysctl -p /etc/sysctl.d/k8s.conf
#如果有如下报错:
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
#解决方法:
#安装bridge-util软件,加载bridge模块,加载br_netfilter模块
yum install -y bridge-utils.x86_64
modprobe bridge
modprobe br_netfilter
#关闭swap
swapoff -a
echo "vm.swappiness=0" >> /etc/sysctl.d/k8s.conf
#使生效
sysctl -p /etc/sysctl.d/k8s.conf
4. 安装软件源配置
#配置k8s软件源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
5. 安装docker
##先校正时间 否则 无法运行docker!!!!
# 1.安装ntpdate工具
sudo yum -y install ntp ntpdate
# 2.设置系统时间与网络时间同步
sudo ntpdate cn.pool.ntp.org
# 3.将系统时间写入硬件时间
sudo hwclock --systohc
# 4.查看系统时间
timedatectl