云原生 API 网关 APISIX入门
365
2022-10-28
外部nginx对接k8s中traefik ingress用于全链路灰度环境
由于k8s是使用的traefik ingress的方式暴露服务,而之前的老环境是直接部署。所以k8s环境中需要传入域名才能正常通过nginx健康检查。check_"GET /actuator/health HTTP/1.1\r\nhost:k8s.example.com\r\n\r\n"; 配置的关键就在这里。之前一直调试了很久都无法成功,如果大家遇到相同的问题可以利用curl命令curl -I -X GET -H host:k8s.example.com k8s.example.com/actuator/health -vv
About to connect() to 192.168.9.178 port 80 (#0) Trying 192.168.9.178... Connected to 192.168.9.178 (192.168.9.178) port 80 (#0) GET /actuator/health HTTP/1.1User-Agent: curl/7.29.0Accept: /host:k8s.example.com < HTTP/1.1 200 OKHTTP/1.1 200 OK< Content-Length: 15Content-Length: 15< Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8< Date: Thu, 28 May 2020 03:32:29 GMTDate: Thu, 28 May 2020 03:32:29 GMT< Server: Server: < Vary: Accept-EncodingVary: Accept-Encoding< X-Envoy-Decorator-Operation: bst-gateway.platform.svc.cluster.local:8080/X-Envoy-Decorator-Operation: bst-gateway.platform.svc.cluster.local:8080/< X-Envoy-Upstream-Healthchecked-Cluster: bst-gateway.platformX-Envoy-Upstream-Healthchecked-Cluster: bst-gateway.platform< X-Envoy-Upstream-Service-Time: 1X-Envoy-Upstream-Service-Time: 1<* Excess found in a non pipelined read: excess = 15 url = /actuator/health (zero-length body)* Connection #0 to host 192.168.9.178 left intact
大于符号是发送到主机的内容,下面的小于符号开始是主机返回的内容。可以根据自己的情况调整check_"GET /actuator/health HTTP/1.1\r\nhost:k8s.example.com\r\n\r\n";的内容。等到所有100%的流量全部切到容器平台以后,之前的老平台也就可以成功下线删除,释放主机资源。然后把这些资源加入到容器平台中。nginx server段的配置:
location /gateway/comment { add_header Access-Control-Allow-Origin *; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header Host $http_host; proxy_set_header Host k8s.example.com; #这个地方要配置成上面健康检查里面的host域名。 proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Port $server_port; proxy_redirect off; proxy_1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_pass http://zt-gateway-k8s; }
这里的host域名配置如何和外网访问相同,可以设置成 $http_host。如果不同,比如用户访问时的域名是gateway.tz.com。而k8s的ingress上配置的域名是k8s.example.com,那就必须配置。否则请求是不会到达k8s上的。经过这样操作大家就不用纠集这整个公司的人力物力停服通宵加班来切换了。而且涉及的人员越多变数越多,失败的概率越大。希望这次经验分享对大家有帮助。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~