| nginx kubernetes gateway 虚拟侵入 |
| https://maimai.cn/article/detail?fid=1770749716&efid=8srfW8D_eCalJEkCh9q_Sw |
|
|
温柔的遥控器
2 年前 |
作者容鑫,API7.ai 云原生技术工程师,Apache APISIX Committer。
Ingress NGINX [1] 是 Kubernetes 社区实现的 Ingress Controller,在社区中被广泛使用。Apache APISIX Ingress [2] 则是 Apache 软件基金会下的开源项目,使用 APISIX 作为数据面的 Kubernetes Ingress Controller。
Ingress NGINX vs APISIX Ingress
功能对比
| Product/Project |
|
Ingress NGINX | Apache APISIX Ingress |
|---|---|---|---|
| 1. General info |
|
|
|
|
|
Based on | nginx | nginx |
| 2. Protocols |
|
|
|
|
|
HTTP/HTTPS | ✔️ | ✔️ |
|
|
HTTP2 | ✔️ | ✔️ |
|
|
gRPC | ✔️ | ✔️ |
|
|
TCP | Partial | ✔️ |
|
|
TCP+TLS | ✖︎ | ✔️ |
|
|
UDP | Partial | ✔️ |
|
|
Websockets | ✔️ | ✔️ |
|
|
Proxy Protocol | ✔️ | ✔️ |
|
|
QUIC/HTTP3 | Preview | Preview |
| 3. Clients |
|
|
|
|
|
Rate limiting (L7) | ✔️ | ✔️ |
|
|
WAF | ✔️ | Partial |
|
|
Timeouts | ✔️ | ✔️ |
|
|
Safe-list/Block-list | ✔️ | ✔️ |
|
|
Authentication | ✔️ | ✔️ |
|
|
Authorisation | ✖︎ | ✔️ |
| 4. Traffic routing |
|
|
|
|
|
Host | ✔️ | ✔️ |
|
|
Path | ✔️ | ✔️ |
|
|
Headers | ✔️ | ✔️ |
|
|
Querystring | ✔️ | ✔️ |
|
|
Method | ✔️ | ✔️ |
|
|
ClientIP | ✔️ | ✔️ |
| 5. Upstream probes/resiliency |
|
|
|
|
|
Healthchecks | ✖︎ | ✔️ |
|
|
Retries | ✔️ | ✔️ |
|
|
Circuit Breaker | ✖︎ | ✔️ |
| 6.Load balancer strategies |
|
|
|
|
|
Round robin | ✔️ | ✔️ |
|
|
Sticky sessions | ✔️ | ✔️ |
|
|
Least connections | ✖︎ | ✔️ |
|
|
Ring hash | ✔️ | ✔️ |
|
|
Custom load balancing | ✖︎ | ✔️ |
| 7. Authentication |
|
|
|
|
|
Basic auth | ✔️ | ✔️ |
|
|
External Auth | ✔️ | ✔️ |
|
|
Client certificate - mTLS | ✔️ | ✔️ |
|
|
OAuth | ✔️ | ✔️ |
|
|
OpenID | ✖︎ | ✔️ |
|
|
JWT | ✖︎ | ✔️ |
|
|
LDAP | ✖︎ | ✔️ |
|
|
HMAC | ✖︎ | ✔️ |
| 8. Observability |
|
|
|
|
|
Logging | ✔️ | ✔️ |
|
|
Metrics | ✔️ | ✔️ |
|
|
Tracing | ✔️ | ✔️ |
| 9. Kubernetes Integration |
|
|
|
|
|
State | Kubernetes | Kubernetes |
|
|
CRD | ✖︎ | ✔️ |
|
|
Scope |
Clusterwide
namespace |
namespace |
|
|
Support for the Gateway API | ✖︎ | Preview |
|
|
Integrates with service meshes | ✔️ | ✔️ |
| 10. Traffic shaping |
|
|
|
|
|
Canary | ✔️ | ✔️ |
|
|
Session Affinity | ✔️ | ✔️ |
|
|
Traffic Mirroring | ✔️ | ✔️ |
| 11. Other |
|
|
|
|
|
Hot reloading | ✔️ | ✔️ |
|
|
LetsEncrypt Integration | ✔️ | ✔️ |
|
|
Wildcard certificate support | ✔️ | ✔️ |
|
|
Configure hot reloading | Preview | ✔️ |
|
|
Service Discovery | ✖ | ✔️ |
功能差异
服务发现
| Service Discovery | Ingress NGINX | Apache APISIX Ingress |
|---|---|---|
| Kubernetes | ✔️ | ✔️ |
| DNS | ✖ | ✔️ |
| nacos | ✖ | ✔️ |
| exureka | ✖ | ✔️ |
| consul_kv | ✖ | ✔️ |
协议支持
两者都对 HTTP/HTTPS 协议提供完整支持,APISIX Ingress 在协议支持上更丰富一些,能够的使用 TLS 来加密 TCP 流量,还支持 MQTT [4] ,Dubbo [5] 、Kafka [6] 等协议进行代理。
服务治理能力
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
name: httpbin
spec:
healthCheck:
passive:
unhealthy:
httpCodes:
- 500
httpFailures: 3
active:
type: http
httpPath: /healthz
healthy:
successes: 3
interval: 2s
httpCodes:
-
200
api-breaker
[7]
熔断插件来实现。具体使用配置示例如下:
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: httpbin-route
spec:
http:
- name: rule1
match:
hosts:
- httpbin.org
paths:
- /status/*
backends:
- serviceName: httpbin
servicePort: 80
plugins:
- name: api-breaker
enable: true
config:
break_response_code: 502
unhealthy:
http_statuses:
- 505
failures: 2
healthy:
http_statuses:
- 200
successes: 2
插件和鉴权方式
apiVersion: apisix.apache.org/v2
kind: ApisixConsumer
metadata:
name: hmac-value
spec:
authParameter:
hmacAuth:
value:
access_key: papa
secret_key: fatpa
algorithm: "hmac-sha256"
clock_skew: 0
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: httpbin-route
spec:
http:
- name: rule1
match:
hosts:
- httpbin.org
paths:
- /ip
backends:
- serviceName: httpbin
servicePort: 80
authentication:
enable: true
type: hmacAuth
Ingress NGINX 和 APISIX Ingress 扩展方式
Ingress NGINX 如何进行功能扩展
example-plugin
/etc/nginx/lua/plugins/<your plugin name>
→
/etc/nginx/lua/plugins/example-plugin
example-plugin
插件,需要在安装 Ingress NGINX 时引用此 ConfigMap 对象
apiVersion: v1
kind: ConfigMap
metadata:
name: ingress-nginx-controller
namespace: ingress-nginx
data:
plugins: "example-plugin"
APISIX Ingress 如何进行功能扩展
为什么 APISIX Ingress 选择维护 CRD
Ingress NGXIN 痛点:不支持配置热加载
静态配置带来的问题
触发 NGINX 重新加载的情况
load-balance
注释不需要重新加载);
小结
云原生新一代网关规范 Gateway API
Gateway API 优势
支持情况
总结
关于 API7.ai
API7.ai(支流科技)是一家提供 API 处理和分析的开源基础软件公司,提供 API 网关、K8s Ingress Controller、Service Mesh 等微服务和实时流量处理的产品和解决方案。致力为全球企业管理并可视化 API 和微服务等关键业务流量,通过大数据和人工智能(AI)加速企业业务决策,驱动数字化转型。