【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

相关推荐
yuluo_YX12 天前
AI Gateway 介绍
人工智能·gateway
网硕互联的小客服15 天前
502 Bad Gateway:服务器作为网关或代理时收到无效响应处理方式
运维·服务器·gateway
sevevty-seven15 天前
什么是Gateway
gateway
秋の花15 天前
【GateWay】和权限验证
java·gateway
欧先生^_^17 天前
org.springframework.cloud.gateway 组件解释
gateway
jarenyVO18 天前
Spring Cloud Gateway 全面学习指南
java·gateway
保持学习ing20 天前
微服务--Gateway网关
java·网关·微服务·gateway
SZ17011023121 天前
IGP(Interior Gateway Protocol,内部网关协议)
运维·服务器·gateway
肥仔哥哥193021 天前
SpringCloud2025+SpringBoot3.5.0+gateway+webflux子服务路由报503
微服务·gateway·最新微服务
亚林瓜子1 个月前
AWS API Gateway配置日志
云计算·gateway·aws·log·cloudwatch