k8s-node2-搭建操作
环境初始化
修改主机名
hostnamectl set-hostname node2
添加本地解析
echo '192.168.20.50 master' >> /etc/hosts
echo '192.168.20.60 node1' >> /etc/hosts
echo '192.168.20.70 node2' >> /etc/hosts
关闭系统防火墙和系统的NetworkManager工具
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
关闭系统的selinux
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0
关闭一些防火墙规则
iptables -F
iptables -X
iptables -Z
iptables -P FORWARD ACCEPT
关闭swap交换分区<<======非常重要
swapoff -a #临时关闭,但是开机还是会开启
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab #防止开机打开swap
修改Linux内核参数,开启数据包转发功能
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward=1
vm.max_map_count=262144
EOF
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
配置NTP
yum -y install ntpdate chrony
systemctl start chronyd
systemctl enable chronyd
ntpdate -u ntp.aliyun.com
hwclock -w
date
配置yum源
下载一些工具包
yum install -y yum-utils device-mapper-persistent-data lvm2
添加Docker源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
添加阿里源
curl -o /etc/yum.repos.d/aliyun.repo https://mirrors.aliyun.com/repo/Centos-7.repo
添加kubernetes源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
清理yun缓存,重建yum缓存
yum clean all
yum makecache -y
yum makecache fast
安装docker环境
yum -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
配置docker加速源
mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://jy4tq1fv.mirror.aliyuncs.com"]
}
EOF
启动docker+开机自启动
systemctl start docker && systemctl enable docker
安装kubernetes环境初始化工具
yum install -y kubelet-1.22.4 kubectl-1.22.4 kubeadm-1.22.4 ipvsadm
启动kubelet+开机自启动
systemctl start kubelet && systemctl enable kubelet
查看版本信息
kubeadm version
加入集群-将master节点保存的token执行
kubeadm join ip --token xxx --discovery-token-ca-cert-hash xxx #这只是样本,不要复制这个