ubuntu kubeadm安装k8s集群
前言
k8s 三master 三node所有节点hosts文件添加
192.168.220.110 master1
192.168.220.120 master2
192.168.220.130 master3
192.168.220.140 node1
192.168.220.150 node2
192.168.220.160 node3
一、初始化所有ubuntu服务器
# 切换用户
sudo su
echo "root:123456" | chpasswd
#修改root用户可登录
sed -i "s+#PermitRootLogin prohibit-password+PermitRootLogin yes+g" /etc/ssh/sshd_config && systemctl restart sshd
#修改dns服务能访问外网
systemctl restart systemd-resolved.service
sed -i "/nameserver/i\nameserver 114.114.114.114" /etc/resolv.conf
sed -i "/nameserver 127.0.0.53/i\nameserver 114.114.114.114" /etc/resolv.conf
##更新软件
apt update
apt upgrade
##安装docker.io docker-compose
apt install -y docker.io docker-compose
## docker daemon.json
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl daemon-reload
#立即启用docker并开机自启
systemctl restart docker
systemctl enable docker
#永久关闭swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
#本地时区设置
timedatectl set-timezone Asia/Shanghai
timedatectl set-local-rtc 0
#取消进程数/连接数限制
-S :soft指定为给定的资源设置软极限。-H :hard
##临时
ulimit -SHn 65535
##永久
说明:* 代表针对所有用户,noproc 是代表最大进程数,nofile 是代表最大文件打开数
cat << EOF >> /etc/security/limits.conf
* soft noproc 65535
* hard noproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
vm.swappiness = 0 # 禁止使用 swap 空间,只有当系统 0OM 时才允许使用它vm.overcommit memory=1 # 不检查物理内存是否够用
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
net.ipv4.ip_forward = 1
EOF
sysctl --system
sysctl -p /etc/sysctl