目录
2.在master01节点基础上,完成master02节点部署
1.部署 CoreDNS
CoreDNS:CoreDNS 是 Kubernetes 的默认 DNS 实现。可以为 K8S 集群内的 Pod 提供 DNS 服务。
使用 CoreDNS 可以为集群中的 service 资源创建一个资源名称 与 ClusterIP 的对应关系解析,从而避免将 service 的 ClusterIP 地址硬编码到应用程序代码中。
两个node节点操作
cd /opt/k8s/
上传coredns.tar包
docker load -i coredns.tar
master01节点操作
cd /opt/k8s/
上传coredns.yaml压缩包
kubectl apply -f coredns.yaml
kubectl get pods -A
2.在master01节点基础上,完成master02节点部署
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/
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
3.部署nginx做负载均衡器
192.168.9.114、192.168.9.115两台服务器做负载均衡
初始化操作
systemctl disable --now firewalld
setenforce 0
两台服务器安装nginx
cd /etc/yum.repos.d/
上传nginx.repo包
yum install -y nginx
192.168.9.114服务器
cd /etc/nginx/
vim nginx.conf
#10行添加 use epoll;
#14行开始添加
stream {
upstream k8s-apiservers {
server 192.168.9.112:6443;
server 192.168.9.116:6443;
}
server {
listen 6443;
proxy_pass k8s-apiservers;
}
}
nginx -t
systemctl enable --now nginx
netstat -lntp | grep nginx
scp nginx.conf 192.168.9.115:`pwd`
192.168.9.115服务器
systemctl enable --now nginx
netstat -lntp | grep nginx
4.部署keepalived做高可用
192.168.9.114、192.168.9.115两台服务器做高可用
yum install -y keepalived
192.168.9.114服务器
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
touch nginx_check.sh
vim nginx_check.sh
#!/bin/bash
if ! killall -0 nginx &> /dev/null
then
systemctl stop keepalived
fi
chmod +x nginx_check.sh
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.9.100
#34行添加
track_script {
nginx_check
}
scp keepalived.conf nginx_check.sh 192.168.9.115:`pwd`
192.168.9.115服务器
cd /etc/keepalived/
vim keepalived.conf
#12行修改
router_id NGINX_02
#22行修改
state BACKUP
#25行修改
priority 90
两台keepalived服务器开启服务
systemctl enable --now keepalived.service
验证keepalived高可用
192.168.9.114服务器操作
192.168.9.115服务器查看vip
将vip漂移至原节点使用
systemctl start nginx keepalived.service ,于192.168.9.114节点操作即可恢复
//修改两个node节点上的bootstrap.kubeconfig,kubelet.kubeconfig配置文件为VIP
cd /opt/kubernetes/cfg/
vim bootstrap.kubeconfig
server: https://192.168.9.100:6443
vim kubelet.kubeconfig
server: https://192.168.9.100:6443
vim kube-proxy.kubeconfig
server: https://192.168.9.100:6443
//重启kubelet和kube-proxy服务
systemctl restart kubelet.service
systemctl restart kube-proxy.service
netstat -natp | grep nginx
若客户端工具也想通过vip链接,可对两个master节点进行以下修改
cd
vim .kube/config
server: https://192.168.9.100:6443