目录
三、在master01节点基础上,完成master02节点部署
五、部署keepalived服务做k8s集群负载均衡器高可用
六、修改node节点上的配置引导文件中的server对应的ip为VIP
七、所有的master节点的集群引导配置文件都指向本机apiserver的ip和端口
一、在所有node节点上部署coreDNS
1.在所有 node 节点上操作
#上传 coredns.tar 到 /opt 目录中
cd /opt
docker load -i coredns.tar
2.在 master01 节点上操作
#上传 coredns.yaml 文件到 /opt/k8s 目录中,部署 CoreDNS
cd /opt/k8s
kubectl apply -f coredns.yaml
kubectl get pods -n kube-system
二、完成master02节点的初始化操作
升级一下组件部署(新增加)
负载均衡节点 | ||
nginx+keepalive01 | 192.168.80.104 (01) | master |
nginx+keepalive02 | 192.168.80.105 (02) | backup |
三、在master01节点基础上,完成master02节点部署
1.在master01 节点操作
master01节点
cd /opt
scp -r etcd/ kubernetes/ master02:/opt
cd
scp -r .kube/ master02:/root
cd /usr/lib/systemd/system
scp kube-* master02:`pwd`
cd /usr/local/bin/
scp kubectl master02:/usr/local/bin/
2.在master02 节点操作
master02节点
cd
cd .kube/
rm -rf cache/
cd /opt/kubernetes/
rm -f logs/*
master02节点
cd /opt/kubernetes/cfg/
vim kube-apiserver
修改为本机ip
systemctl enable --now kube-apiserver.service kube-controller-manager.service kube-scheduler.service
systemctl status kube-apiserver.service kube-controller-manager.service kube-scheduler.service
查看验证master02节点
kubectl get nodes
kubectl get pods -A
kubectl get svc
四、部署nginx做负载均衡器
记得关闭防火墙
1.在01 节点上操作
192.168.80.104
//配置nginx的官方在线yum源,配置本地nginx的yum源
cat > /etc/yum.repos.d/nginx.repo << 'EOF'
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
EOF
yum install nginx -y
修改nginx配置文件,配置四层反向代理负载均衡,指定k8s群集2台master的节点ip和6443端口
vim /etc/nginx/nginx.conf
events {
use epoll
worker_connections 1024;
}
#添加
stream {
upstream k8s-apiserver {
server 192.168.80.100:6443;
server 192.168.80.101:6443;
}
server {
listen 6443;
proxy_pass k8s-apiserver;
}
}
//检查配置文件语法
nginx -t
//启动nginx服务,查看已监听6443端口
systemctl start nginx
systemctl enable nginx
netstat -natp | grep nginx
复制过去
scp nginx.conf 192.168.80.105:`pwd`
2.在02 节点上操作
192.168.80.105
没问题
五、部署keepalived服务做k8s集群负载均衡器高可用
1.先将01,02两个节点都安装keepalived
yum install -y keepalived
2.在01 节点上操作
创建nginx状态检查脚本
touch nginx_check.sh
chmod +x nginx_check.sh
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vim nginx_check.sh
#!/bin/bash
if ! killall -0 nginx &> /dev/null
then
systemctl stop keepalived
fi
chmod +x nginx_check.sh
修改keepalived配置文件
vim keepalived.conf
#10行修改
smtp_server 127.0.0.1
#12行修改
router_id NGINX_01
删除原本13-16行
#15行添加
vrrp_script nginx_check {
script "/etc/keepalived/nginx_check.sh"
weight 2
interval 2
}
#23行修改为本机网卡
interface ens33
#32行修改为指定vip
192.168.80.200
#34行添加
track_script {
nginx_check
}
scp keepalived.conf nginx_check.sh 192.168.80.105:`pwd`
3.在02 节点上操作
vim /etc/keepalived/keepalived.conf
4.在01 节点上操作
systemctl enable --now keepalived.service
ip a
关闭nginx服务
systemctl stop nginx
5.在02 节点上操作
systemctl enable --now keepalived.service
ip a
6.在01 节点上操作
systemctl start nginx keepalived.service
六、修改node节点上的配置引导文件中的server对应的ip为VIP
1.node01 和node02 相同操作
//修改两个node节点上的bootstrap.kubeconfig,kubelet.kubeconfig配置文件为VIP
cd /opt/kubernetes/cfg/
vim bootstrap.kubeconfig
server: https://192.168.80.200:6443
vim kubelet.kubeconfig
server: https://192.168.80.200:6443
vim kube-proxy.kubeconfig
server: https://192.168.80.200:6443
//重启kubelet和kube-proxy服务
systemctl restart kubelet.service
systemctl restart kube-proxy.service
剩下两个也是一样修改成
192.168.80.200(vip地址)
2.去01 节点查看
netstat -natp | grep nginx
七、所有的master节点的集群引导配置文件都指向本机apiserver的ip和端口
在两个master节点修改
将原来的ip修改成vip地址
192.168.80.200
检察一下
kubectl get nodes
kubectl get svc
kubectl get cs
k8s集群已经部署完毕了
终于可以使用了!!!