

Kong网关极简入门
source link: https://sund.site/posts/2023/kong-gateway/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Kong Gateway is a Lua application running in Nginx. Kong Gateway is distributed along with OpenResty, which is a bundle of modules that extend the lua-nginx-module.
Kong 是一个基于 Nginx 上运行的 Lua 程序。它改善了 Nginx 基于静态配置的缺点,可以动态添加插件和热部署。

Kong 的基础模块
Service是后端服务的抽象。
Routes是 client 到后端服务的路由规则的抽象。如,为不同的 client 设置不同的认证规则。
Kong 的 routes 有两种模式 traditional_compat
和 expressions
。
traditional_compat
:旧的基于通配符等匹配优先级的模式。expressions
:新的基于表达式的匹配模式。
Upstreams是一个运维对象,在 Services 和真正的后台 API 服务之间,用来负载均衡。
Plugins是用 lua 或 go 编写的插件,分为 Kong 官方提供的插件和第三方插件。
Kong 的工作原理
Kong 支持三类协议:HTTP/HTTPS,TCL/TLS 和 GRPC/GRPCS。每种协议由不同的参数组成:
http
:methods
,hosts
,headers
,paths
(andsnis
, ifhttps
)tcp
:sources
,destinations
(andsnis
, iftls
)grpc
:hosts
,headers
,paths
(andsnis
, ifgrpcs
)
Kong 支持按 HTTP header、URL、method、源地址、目标地址、Server Name Indication 来路由请求。
Kong 默认以RFC 3986协议对请求的路径处理。
Kong 匹配规则的优先级
按最多匹配的规则来路由。
The rule is: when evaluating a request, Kong Gateway first tries to match the routes with the most rules.
当所有匹配规则检查完,Kong 会通过下层的 Nginx 模块发送请求。Response 返回之后,Kong 再经过header_filter
和body_filter
两个 hook 来修改 response header 和 body。
对 WebSocket 的支持
有两种配置方式来路由 wss 请求:
- HTTP(S) services and routes:把 wss 流量当作不透明的字节流。
- WS(S) services and routes (企业版功能):可以更好的用 websocket 插件控制流量。
Kong 支持两类负载均衡方式
- 基于 DNS (服务注册和发现是静态的)
- 基于哈希环的动态负载均衡(服务注册发现由 Kong 管理,可以动态增删)
这部分跟 Nginx 类似。
- active checks(心跳检查)
- passive checks(被动检查,即断路器,根据流量检查)
Recommend
-
62
在微服务架构之下,服务被拆的非常零散,降低了耦合度的同时也给服务的统一管理增加了难度。如上图左所示,在旧的服务治理体系之下,鉴权,限流...
-
8
整合一套高性能网关Kong 前言# 相信大家...
-
4
Kong网关初探 祈雨的博客 2021-03-07 架构 ...
-
8
Api网关Kong集成Consul做服务发现及在Asp.Net Core中的使用
-
6
Kong 由 Mashape 公司开源,是一款高性能高可用的微服务网关,是基于 OpenResty(Nginx + Lua模块)编写的高可用服务网关,由于 Kong 是基于 Nginx 的,因此可以很轻松地水平扩展 Kong 服务器。通过负载均衡把请求转发给各个服务端实例,来应对大批量的网...
-
6
C#/.net/.net core QQ群:953553560.NET技术分享公众号...
-
5
Jager · 11月7日 · 2021年APISIX · API网关 · nginx 53次已读 一、需求背景 博客前文...
-
4
Kong 1.0发布,从网关转型为服务控制平台 · Service Mesh|服务网格中文社区
-
3
微服务网关 Kong 科普 2022年08月19日 10:16 · 阅读 530 Kong 是由 Mashape 开发的...
-
10
API网关:Apache APISIX 3.0与Kong 3.0比较 2022 年 9 月...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK