NGINX 向云原生演进,All in OpenNJet 概述
资源变化
|
OpenNJet配置信息变化方式
| ||
Ingress资源变化
|
删除新建
|
Ingress
|
动态location API
动态Upstream API
|
内容
|
host
|
动态location API
| |
path
|
动态location API
| ||
service
|
动态Upstream API
| ||
pod动态扩缩容
|
|
endpoint
|
动态Upstream API
|
header
、
cookie
、
argument
、
variable
。
以下是一个VS的示例:
apiVersion: k8s.njet.org/v1
kind: VirtualServer
metadata:
name: cafe
namespace: default
spec:
host: cafe.example.com.vs
routes:
- action:
pass: details
matches:
- action:
pass: tea-post
conditions:
- value: POST
variable: $request_method
path: ~* \.html$
- action:
pass: ratings
matches:
- action:
pass: productpage
conditions:
- cookie: version
value: v2
- value: GET
variable: $request_method
path: /productpage
upstreams:
- name: ratings
port: 9080
service: ratings
- name: productpage
port: 9080
service: productpage
- name: tea-post
port: 80
service: tea-post-svc
- name: details
port: 9080
service: details
上图VS中,配置了两个路由:
tea-post
upstream,其他请求被路由到
details
upstream(默认处理))
productpage
upstream,其他请求被路由到
ratings
upstream(默认处理))
OpenNJet KIC配置当中会生成一个默认的被称为"upstream_balancer"的upstream,此upstream会处理所有路由。当真实流量到来时,会交由内部lua上下文处理。"upstream_balancer"配置如下:
upstream upstream_balancer {
### Attention!!!
#
# We no longer create "upstream" section for every backend.
# Backends are handled dynamically using Lua.
#
###
server 0.0.0.1; # placeholder
balancer_by_lua_block {
balancer.balance()
}
keepalive 320;
keepalive_time 1h;
keepalive_timeout 120s;
keepalive_requests 10000;
}
hash key
|
描述
|
$arg_{VAR}
|
根据url 传递的参数 VAR 做一致性hash
|
$http_{NAME}
|
根据HEADER 传递的参数 NAME 做一致性hash
|
$cookie_{NAME}
|
根据 Cookie 传递的参数 NAME 做一致性hash
|
$remote_addr
|
根据客户端的IP做一致性hash
|
vstest.example.com
与
a.test.com
对应的证书进行关联。
KIC 服务中通过注解Annotations 声明Prometheus 指标的采集端口及路径。配置如下:
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/port: "12001"
prometheus.io/scheme: http
prometheus.io/scrape: "true"
prometheus.io/path: "/stats"
name: njet-ingress
namespace: njet-ingress
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
selector:
app: njet-ingress
OpenNJet 最早是基于 NGINX1.19 基础 fork 并独立演进,具有高性能、稳定、易扩展的特点,同时也解决了 NGINX 长期存在的难于动态配置、管理功能影响业务等问题。
|