搭建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会路由到不同的后端服务。

相关推荐
Yana.nice8 小时前
Linux 只保留 30 天内日志(find命令删除日志文件)
linux·运维·chrome
2601_9605679610 小时前
电商套图自动化效率的工程量化分析——从逐张生成到批量套图的架构演进
运维·架构·自动化
吳所畏惧11 小时前
宝塔面板Redis密码修改指南:SSH命令修改 vs 面板UI界面修改,哪个更靠谱?
运维·服务器·数据库·redis·缓存·ssh
HiDev_12 小时前
【非标自动化】2、认识元器件(确定目标)
运维·自动化
Zhang~Ling13 小时前
从 fopen 到 struct file:从零开始拆解 Linux 文件 I/O
linux·运维·服务器
爱写代码的森13 小时前
蒙三方库 | harmony-utils之FileUtil文件重命名与属性查询详解
linux·运维·服务器·华为·harmonyos·鸿蒙·huawei
中微极客13 小时前
2026主流AI Agent框架技术选型与性能对比
运维·网络·人工智能
久曲健的测试窝13 小时前
智能座舱自动化测试落地方案:数字仿真搭配实车实测,解决用例运维与场景失真难题
运维
郝亚军14 小时前
使用Vue 3和Nginx打包和部署Vue.js项目的一般步骤
前端·vue.js·nginx