搭建nginx的负载均衡

1、编写一个configMap的配置文件

复制代码
events {
    worker_connections 1024;  # 定义每个worker进程的最大连接数
}

http {
    # 定义通用代理参数(替代proxy_params文件)
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    
    proxy_connect_timeout 5s;
    proxy_read_timeout 10s;
    proxy_send_timeout 10s;
    
    proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
    proxy_next_upstream_tries 3;

    upstream backend {
        #ip_hash;  # 基于客户端IP的会话保持
        server 172.16.45.33:8081 max_fails=3 fail_timeout=30s;
        server 172.16.45.33:8084 max_fails=3 fail_timeout=30s;
    }

    server {
        listen 8045;
        
        location / {
            proxy_pass http://backend;
            
            # 如果不需要单独的proxy_params文件,可以在这里直接包含参数
            # 或者保留include指令但确保文件存在
        }
        
        # 添加健康检查端点
        location = /health {
            access_log off;
            return 200 "OK";
            add_header Content-Type text/plain;
        }
    }
}

如下,key为nginx.conf

2、把该configMap的配置文件映射到容器的/ect/nginx/目录下

3、点击保存,后会启动nginx的服务。

4、访问http://ip:8045会路由到不同的后端服务。

相关推荐
鸠摩智首席音效师6 小时前
linux 系统中 Shutting Down, Restarting, Halting 有什么区别 ?
linux·运维·服务器
CIb0la6 小时前
Linux 将继续不支持 HDMI 2.1 实现
linux·运维·服务器
吕了了7 小时前
85 微PE吕了了修改版--更新!
运维·windows·电脑·系统
鹿鸣天涯7 小时前
Kali Linux 2025.4 发布:桌面环境增强,新增 3 款安全工具
linux·运维·安全
学习&笔记8 小时前
MTK(系统篇)user版本无法使用setenforce 0命令关闭selinux权限
linux·运维·服务器
Bdygsl8 小时前
Linux(8)—— 进程优先级与环境变量
linux·运维·服务器
吕了了8 小时前
87 Windows 系统安装的本质是什么?
运维·windows·电脑·系统
阿里巴巴P8资深技术专家9 小时前
docker容器启动报错
运维·docker·容器
杨云龙UP9 小时前
MySQL 8.0.x InnoDB 写入链路优化:Redo Log 与 Buffer Pool 扩容与缓冲区调优实战记录-20251029
linux·运维·数据库·sql·mysql
txzz888810 小时前
CentOS-Stream-10 系统安装之网络设置
linux·运维·服务器·网络·计算机网络·centos