简单易懂的Kubernetes(K8S)负载均衡部署详细步骤

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

注意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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清风~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值