惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
U
Unit 42
B
Blog RSS Feed
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
腾讯CDC
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - 聂微东
MyScale Blog
MyScale Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta

小松鼠的博客

记录一次线上k8s工作节点无法创建容器的问题排查思路与解决办法 记一次线上GoLang项目OOM排查过程 从LastPass转向拥抱开源KeePass的心路历程 故障定位与 AI 结合前后端编码实践 FileBeat收集nginx-ingress-controller日志 K8s云原生环境下文件描述符占用过高查询思路 2024年最新关闭火绒安全工具的开机自启方法 Kubernetes任务调度实践-Go语言实现Job和CronJob对比分析 离线更新k8s环境下的trivy漏洞库方法 使用Go语言接入Choerodon实现基于OAuth2的统一身份认证登录 在Vue2中自定义Switch组件并实现父子组件双向数据绑定 关于docker jdk1.8镜像中的GB18030-2022标准支持及验证 Go框架gin中的session存储gin-contrib-sessions和go-session 关于修改node_module中的源码问题记录 docker-compose网络和内网服务IP冲突问题 慎用存储过程:一条语句引发的数据库存储100%占用 Spring Boot中4种文件下载方法的实现 避坑-不能将specific类型的gitlab-runner改变为share类型 Docker compose中的MySQL主从复制模式和percona-toolkit工具使用 在minio中开启https访问以及使用rclone备份minio桶 在多机Docker环境下部署Choerodon的解决方案 Prometheus中Monitor添加对SpringBoot Actuator的Basic认证 在Nginx的容器镜像中隐藏Nginx的Server响应头 两个docker工具:runlike和whaler Grafana中的邮件报警和截图插件grafana-image-enderer K8s中externalName-service和services-without-selectors maven配置文件settings.xml中的一些概念总结 K8s中flexvolume插件驱动的安装 K8s中的coredns无法解析svc问题排查 K8s中使用Ingress访问请求体过大问题解决
K8s中的两种nginx-ingress-controller及其区别
ycyin · 2022-11-17 · via 小松鼠的博客

2022年11月16日大约 4 分钟云原生k8snginx-ingress


有两种基于 NGINX 的 Ingress 控制器实现:一种是nginxinc/kubernetes-ingress,另一种是kubernetes/ingress-nginx

什么是Ingress Controller?

为了让 Ingress 资源工作,集群中至少要有一个 Ingress Controller运行。 Ingress Controller抽象出 Kubernetes 应用程序流量路由的复杂性,并在 Kubernetes 服务和外部服务(外部世界)之间提供桥梁。[1]

您可以在集群中部署多个 Ingress Controller。这需要在创建 Ingress 时,使用适当的 ingress.class 注解 Ingress,以标识应使用哪个 Ingress Controller。如果没有定义指定,则使用默认的Ingress Controller。

一般情况下,所有Ingress Controller都应满足此规范,但各种Ingress Controller的操作略有不同。

目前有两种基于 NGINX 的 Kubernetes Ingress Controller——它们都是开源的并托管在 GitHub 上。一个是K8s开源社区的kubernetes/ingress-nginx,另一个是Nginx官方的nginxinc/kubernetes-ingress

主要区别

Kubernetes Ingress Controller

这是k8s官方社区开发维护的控制器,它是基于Nginx的,扩展功能则需要使用Lua插件实现。

NGINX Ingress Controller

这是由nginx的官方开发维护的控制器,它还有一个基于Nginx Plus的商业版本。NGINX 控制器具有高稳定性、持续向后兼容性、没有任何第三方模块、由于没有Lua 代码更高效(与k8s官方控制器相比)。

即使与官方控制器相比,免费软件版本也受到很大限制(由于没有Lua 模块)。同时,付费版本拥有相当广泛的附加功能:实时指标、JWT 验证、主动健康检查等。

关于 nginxinc/kubernetes-ingresskubernetes/ingress-nginx 的更多区别可见下表[2]:

Aspect or Featurekubernetes/ingress-nginxnginxinc/kubernetes-ingress with NGINXnginxinc/kubernetes-ingress with NGINX Plus
Fundamental
AuthorsKubernetes communityNGINX Inc and communityNGINX Inc and community
NGINX versionCustom NGINX build that includes several third-party modulesNGINX official mainline buildNGINX Plus
Commercial supportN/AN/AIncluded
Implemented inGo/Lua (while Nginx is written in C)Go/PythonGo/Python
Load balancing configuration via the Ingress resource
Merging Ingress rules with the same hostSupportedSupported via Mergeable IngressesSupported via Mergeable Ingresses
HTTP load balancing extensions - AnnotationsSee the supported annotationsSee the supported annotationsSee the supported annotations
HTTP load balancing extensions -- ConfigMapSee the supported ConfigMap keysSee the supported ConfigMap keysSee the supported ConfigMap keys
TCP/UDPSupported via a ConfigMapSupported via custom resourcesSupported via custom resources
WebsocketSupportedSupported via an annotationSupported via an annotation
TCP SSL PassthroughSupported via a ConfigMapSupported via custom resourcesSupported via custom resources
JWT validationNot supportedNot supportedSupported
Session persistenceSupported via a third-party moduleNot supportedSupported
Canary testing (by header, cookie, weight)Supported via annotationsSupported via custom resourcesSupported via custom resources
Configuration templatesSee the templateSee the templatesSee the templates
Load balancing configuration via Custom Resources
HTTP load balancingNot supportedSee VirtualServer and VirtualServerRoute resourcesSee VirtualServer and VirtualServerRoute resources
TCP/UDP load balancingNot supportedSee TransportServer resourceSee TransportServer resource
TCP SSL Passthrough load balancingNot supportedSee TransportServer resourceSee TransportServer resource
Deployment
Command-line argumentsSee the argumentsSee the argumentsSee the arguments
TLS certificate and key for the default serverRequired as a command-line argument/ auto-generatedRequired as a command-line argumentRequired as a command-line argument
Helm chartSupportedSupportedSupported
OperatorNot supportedSupportedSupported
Operational
Reporting the IP address(es) of the Ingress controller into Ingress resourcesSupportedSupportedSupported
Extended StatusSupported via a third-party moduleNot supportedSupported
Prometheus IntegrationSupportedSupportedSupported
Dynamic reconfiguration of endpoints (no configuration reloading)Supported with a third-party Lua moduleNot supportedSupported

实际使用差别

当我们实际使用上述两个版本的Ingress控制器(Nginx官方和Kubernetes官方)时,特别需要注意的就是他们所支持的Annotation不同(这也是在我工作中经常处理遇到的问题,经常搞混导致设置不生效),比如下面的这个问题:

我们有一个数据量大的导出接口阻塞等待大约5分钟,每次在刚好1分钟时接口报错504 Gateway Time-out,怎么处理?

如果只是nginx,这只需要设置nginx的proxy_read_timeout(顾名思义这个参数是设置nginx代理读取超时时间,默认60s)即可。比如proxy_read_timeout 600s

对于kubernetes/ingress-nginx需要使用nginx.ingress.kubernetes.io/proxy-read-timeout: "600"

对于nginxinc/kubernetes-ingress with NGINX需要使用nginx.org/proxy-read-timeout: "10m"

更多注解上的使用区分可查看kubernetes/ingress-nginxnginxinc/kubernetes-ingress with NGINX

参考:


  1. https://grigorkh.medium.com/there-are-two-nginx-ingress-controllers-for-k8s-what-44c7b548e678 ↩︎

  2. https://gist.github.com/grigorkh/f8e4fd73e99f0fde06a51e2ed7c2156c ↩︎