CentOS Stream kubernetes 前面增加一个nginx转发

今天帮朋友在kubernetes前面加一个nginx , 然后配置的过程中发现还是有一些细节的问题已经记不清楚了,现查了文档, 所以这里记录一下过程中一些配置,方便以后能快速的拿出来用。
这里不会介绍安装方法, 一是不复杂,二是网上很多教程和资料,三就是不是本文的主要想说的内容。

后续有配置更新或者需要注意的地方会随时更新本文。

  1. 前置条件
  • k8s 和 istio 以及 pod正常运行
  1. 查看istio 对外的接口
    这里分两种情况,一种是有外部负载均衡,另一种是没有外部负载均衡, 两种查询端口的方式是不一样的。
    参考资料 : https://istio.io/latest/zh/docs/setup/getting-started/#确定入站-ip-和端口
    我这里是没有外部负载均衡的,命令如下
[root@master-01 conf.d]# export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
[root@master-01 conf.d]# export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
[root@master-01 conf.d]#
[root@master-01 conf.d]# echo $INGRESS_PORT
32084
  1. nginx 配置 创建一个 test-qingfeng.run.conf 配置文件, 内容入下
upstream k8s {
    server 10.26.44.186:32084; #node节点ip:端口号,  端口号是上面查出来的
}

server {
    listen 80;    # 本地nginx 端口
    server_name test.qingfeng.run;  # 对外域名
    location / {
        proxy_http_version 1.1;         # http 版本, 这里要设置成1.1,   如果不配置可能出现http 426状态码等
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;      # 这个一定要有, 到k8s里面 vs要根据这个查找service
        proxy_pass http://k8s; #代理至集群名称
    }
}
posted @ 2022-02-26 15:26  zzphper  阅读(118)  评论(0编辑  收藏  举报