一、背景
二、K8s Ingress安装
ingress 官方网站:https://kubernetes.github.io/ingress-nginx/
ingress 仓库地址:https://github.com/kubernetes/ingress-nginx
三、K8s Ingress rewrite 讲解与使用
1)配置说明
Ingress rewrite实现是通过在下添加对应的字段,annotations 参数说明:
想了解更多annotations参数,可以参考官方文档:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/
2)示例演示
1、部署应用
2、配置ingress rewrite转发(http)
【示例1】
【示例2】域名转发
配置hosts
http://ingress-http-test2.com/nginx-1/
http://ingress-http-test2.com/apache-1/
3、配置ingress rewrite转发(https)【1】创建证书(有证书可忽略)
首先需要证书,如果没有证书,可以按照下面命令创建证书
【2】创建 Secret
【3】Ingress引用Secret资源实现HTTPS
https://ingress-http-test2.com/nginx-1/
https://ingress-http-test2.com/apache-1/
四、K8s Ingress TCP四层转发
Ingress配置转发端口本质,还是利用service nodePort能力,通过暴露ingress的本地端口来转发。Ingress 默认不支持TCP or UDP services。因此Ingress controller使用和这两个配置达到转发端口的目的。
1)开启tcp/udp转发
检查nginx-ingress是否开启tcp/udp转发,如果没开启,需要修改deployment ingress-nginx的参数配置,添加–tcp-service-configmap,如下:
执行更新
2)部署应用(mysql)
3)更改ingress-nginx的service,声明tcp和udp用的端口号
3)定义configmap
格式为"。
例如下面配置的data第一行表示将命名空间下的服务的端口映射到ingress-controller service的端口,即可通过ingress-controller的service ip加端口访问到服务。
4)检查
进入nginx-ingress容器查看TCP services处会出现对应的负载配置
领取专属 10元无门槛券
私享最新 技术干货