【kong gateway】5分钟快速上手kong gateway

kong gateway的请求响应示意图

安装
下载对应的docker 镜像

可以直接使用docker pull命令拉取,也可以从以下地址下载:kong gateway 3.9.0.0 docker 镜像 https://download.csdn.net/download/zhangshenglu1/90307400, postgres-13.tar https://download.csdn.net/download/zhangshenglu1/90307408

下载完成后,通过如下命令加载镜像

sh 复制代码
# 导入 kong-gateway 镜像
docker load -i /path/to/destination/kong-gateway-3.9.0.0.tar

# 导入 postgres 镜像
docker load -i /path/to/destination/postgres-13.tar
kong的安装命令

通过下面的地址下载对应的安装脚本

https://download.csdn.net/download/zhangshenglu1/90307411

下载完成后执行脚本

sh 复制代码
sh kong_install.sh
Service
概念

​ 在 Kong Gateway 中,服务(Service)是对现有上游应用程序的抽象。服务可以存储诸如插件配置、策略等对象的集合,并且可以与路由(Route)相关联。

定义服务时,管理员需要提供服务的名称和上游应用程序的连接信息。连接详情可以通过 url 字段以单个字符串形式提供,或者分别提供 protocolhostportpath 的独立值。

服务与上游应用程序之间具有一对多的关系,这使管理员能够创建复杂的流量管理行为。

创建service

url:http://192.168.188.101:8001/services

method: POST

body:

json 复制代码
{
    "name":"my_service",
    "host":"my_upstream"
}
Route
概念

在 Kong Gateway 中,路由通常映射到通过 Kong Gateway 应用程序暴露的端点(endpoints)。路由还可以定义规则,用于将请求匹配到关联的服务。因此,一个路由可以引用多个端点。一个基本的路由应包含名称、路径或多个路径,并引用一个已存在的服务。

创建route

url: http://192.168.188.101:8001/services/my_service/routes

method: POST

body

json 复制代码
{
    "name":"my_route",
    "paths":["/my_service"]
}
Upstream
概念

​ 它负责管理多个 Target,并定义了这些服务节点的属性,如健康检查、负载均衡策略等。通过 Upstream,Kong 可以将客户端请求分发到后端服务。

创建upstream

url: http://192.168.188.101:8001/upstreams

method: POST

body:

json 复制代码
{
  "name": "my_upstream",
  "algorithm": "round-robin",
  "healthchecks": {
    "active": {
      "https_verify_certificate": true,
      "healthy": {
        "http_statuses": [
          200,
          302
        ],
        "successes": 1,
        "interval": 2
      },
      "unhealthy": {
        "http_failures": 2,
        "http_statuses": [
          429,
          404,
          500,
          501,
          502,
          503,
          504,
          505
        ],
        "timeouts": 3,
        "tcp_failures": 2,
        "interval": 2
      },
      "type": "http",
      "concurrency": 2,
      "http_path": "/health"
 
    }
  }
}
target
概念

Target 是指 Upstream 中的具体服务节点。简单来说,Target 是指向某个具体后端服务的单一实例或服务器。在 Kong 中,Upstream 是用于管理一组 Target 的集合,它代表了一个上游服务的代理,而 Target 则是 Upstream 中的实际服务节点,通常是具体的服务器或容器的 IP 地址和端口。

给upstream绑定target

url:http://192.168.188.101:8001/upstreams/my_upstream/targets

method: POST

body:

json 复制代码
{
  "target": "192.168.188.108:8174",
  "weight": 100
}
检查target的是否健康

url: http://192.168.188.101:8001/upstreams/my_upstream/health

method: GET

测试kong 网关的链路

192.168.188.101:8000/my_service/health

相关推荐
三口吃掉你1 天前
微服务之网关(Spring Cloud Gateway)
java·网关·微服务·gateway
余衫马2 天前
微服务SpringCloud报错合集
spring boot·gateway
Zz_waiting.2 天前
统一服务入口-Gateway
java·开发语言·gateway
菲兹园长3 天前
微服务组件(E、L、N、O、G)
linux·服务器·gateway
tuokuac6 天前
依赖spring-cloud-starter-gateway与spring-cloud-gateway-dependencies的区别
java·gateway
洛克大航海7 天前
9-SpringCloud-服务网关 Gateway-高级特性之 Filter-2
java·spring cloud·gateway·filter
洛克大航海8 天前
9-SpringCloud-服务网关 Gateway-高级特性之 Filter-1
spring·spring cloud·gateway·filter
yangmf20409 天前
如何使用 INFINI Gateway 增量迁移 ES 数据
大数据·数据库·elasticsearch·搜索引擎·gateway
非凡的世界10 天前
ThinkPHP6 集成TCP长连接 GatewayWorker
网络·网络协议·tcp/ip·gateway·thinkphp·worker·workman
戮戮10 天前
一次深入排查:Spring Cloud Gateway TCP 连接复用导致 K8s 负载均衡失效
tcp/ip·spring cloud·kubernetes·gateway·负载均衡·netty