文章目录
注意:K8S负载均衡部署是在K8S多节点全部部署完成以后进行的部署
LB01:192.168.200.70
LB01:192.168.200.80
-----lb01 lb02两台负载均衡服务器均执行以下操作-----
1、关闭防火墙
[root@lb1 ~]# systemctl stop firewalld.service
[root@lb1 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@lb1 ~]# setenforce 0
[root@lb1 ~]# iptables -F
[root@lb1 ~]#
2、安装nginx服务,把nginx.sh和keepalived.conf脚本拷贝到家目录
[root@lb1 ~]# ls
anaconda-ks.cfg keepalived.conf 公共 视频 文档 音乐
initial-setup-ks.cfg nginx.sh 模板 图片 下载 桌面
[root@lb1 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@lb1 ~]# yum install nginx -y
3、添加四层转发
[root@lb1 ~]# vim /etc/nginx/nginx.conf
events {
worker_connections 1024;
}
stream {
log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';
access_log /var/log/nginx/k8s-access.log main;
upstream k8s-apiserver {
server 192.168.195.149:6443; #修改为master1的IP
server 192.168.195.131:6443; #修改为master2的IP
}
server {
listen 6443;
proxy_pass k8s-apiserver;
}
}
http {
[root@lb1 ~]# systemctl start nginx
4、部署keepalived服务
[root@lb1 ~]# yum install keepalived -y
5、修改配置文件
[root@lb1 ~]# cp keepalived.conf /etc/keepalived/keepalived.conf
cp:是否覆盖"/etc/keepalived/keepalived.conf"? yes
//注意:lb01中Master配置如下:
[root@lb1 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
# 接收邮件地址
notification_email {
acassen

本文档详细介绍了在K8S环境中使用Nginx和Keepalived实现负载均衡的步骤,包括关闭防火墙、安装Nginx服务、配置四层转发、部署Keepalived服务、修改配置文件、编写监控脚本、验证VIP以及在Node节点上的配置等。通过这些操作,确保了K8S集群的高可用性和稳定性。
最低0.47元/天 解锁文章
1632

被折叠的 条评论
为什么被折叠?



