说明:本系列文章介绍的是用kubeadmin方式搭建kubernetes集群
阶段一:
1.环境准备
需准备3台centos7.0 x64 server 并且内核版本在4.0以上(一定要4.0以上否则会出现bug)
2.修改集群里主机的hostname (集群里hostname 名称不能重复)
hostnamectl set-hostname 名称 eg:
hostnamectl set-hostname k8s01
3. hostname 命令可以查看该主机的主机名称
4.安装依赖包
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
5.关闭防火墙 swap 重置iptables
5.1 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
5.2 重置iptables 并设置为空规则
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables&& iptables -F && service iptables save
5.3 关闭swap
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
5.4 禁止开机启动
sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab
5.5 关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
5.6 关闭dnsmasq (否则导致docker容器无法解析域名)
service dnsmasq stop && systemctl disable dnsmasq
6.系统参数设置 直接复制下面的命令
cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它vm.overcommit_memory=1 # 不检查物理内存是否够用
vm.panic_on_oom=0 # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
7.将上面得到的kubernetes.conf 拷贝到 /etc/sysctl.d/
cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
8.设置kubernetes.conf开机就会被调用
sysctl -p /etc/sysctl.d/kubernetes.conf
注意:如步骤8 报以下错误:
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
9.设置系统时区为中国/上海 (如果时区已经是上海了则跳过此步骤)
timedatectl set-timezone Asia/Shanghai
9.1将当前的 CST时间写入硬件时钟
timedatectl set-local-rtc 0
9.2重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond
10.关闭系统不需要的服务
systemctl stop postfix && systemctl disable postfix
11.设置 rsyslogd 和 systemd journald
11.1 创建持久化保存日志的目录
mkdir /var/log/journal
mkdir /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF
[Journal]
# 持久化保存到磁盘
Storage=persistent
# 压缩历史日志
Compress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=1000
# 最大占用空间 10G
SystemMaxUse=10G
# 单日志文件最大 200M
SystemMaxFileSize=200M
# 日志保存时间 2 周
MaxRetentionSec=2week
# 不将日志转发到 syslog
ForwardToSyslog=no
EOF
11.2重启 journald
systemctl restart systemd-journald
12.kube-proxy开启ipvs的前置条件 (提高性能) 每个节点
12.1 向内核加载模块
modprobe br_netfilter
12.2
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
12.3 赋予 755权限 然后查看这些模块是否被引导
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules &&lsmod | grep -e ip_vs -e nf_conntrack_ipv4
本章完