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

相关推荐
-dzk-4 小时前
【3DGS复现】Autodl服务器复现3DGS《简单快速》《一次成功》《新手练习复现必备》
运维·服务器·python·计算机视觉·3d·三维重建·三维
CS Beginner4 小时前
【Linux】 Ubuntu 开发环境极速搭建
linux·运维·ubuntu
致宏Rex5 小时前
Docker 实战教程(7) | 镜像管理和仓库操作
运维·docker·容器
wu~9707 小时前
web服务器有哪些?服务器和web服务器有什么区别
运维·服务器·前端
爱倒腾的老唐7 小时前
13、Linux 基本权限
linux·运维·服务器
罗政7 小时前
CentOS 7.6 系统源码部署 HivisionIDPhotos
linux·运维·centos
薰衣草23339 小时前
linux练习-2
linux·运维·服务器
DrugOne10 小时前
Amber24 安装指南:Ubuntu 22.04 + CUDA 12.4 环境
linux·运维·ubuntu·drugone
洋葱圈儿66610 小时前
第八个实验——浮动路由
运维·服务器·网络
yunmi_11 小时前
Spring Cloud Netfilx -- Ribbon:负载均衡工具(代码示例)
spring cloud·ribbon·maven·负载均衡