Companies use K8S set up a test environment, and there are multiple sets of test change, current thinking is that every test environment using a set of export IP.
Program:
1. build Ingress
2. By building a reverse proxy
Combined with the actual situation, we use a reverse proxy set up to solve this problem.
In our environment there K8S service
vipapi-mall-com #-based .netcore
billapi # COM-Mall-based PHP
the WWW COM #-Mall-based PHP
VUE-based mobile-mall-com #
vipapi-mall-com domain name is the external vipapi.mall.com
billapi-Mall-COM external domain name is billapi.mall.com
kubernetes of KUBE-DNS address is 10.254.0.2, using coredns
us there is a namespace
branches
Tags
Configuration files are as follows:
upstream vipapi {
server vipapi-mall-com; #正常情况这里放是会出错的,但是如果加了reslover就不会报错了,这里填写K8S的service名称即可
}
server {
listen 80;
server_name vipapi.mall.com;
access_log off;
resolver 10.254.0.2; #注意DNS解析的配置必须放在server下不能放在location下,否则无法解析
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_pass http://vipapi;
}
}