【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

相关推荐
tnan25223 天前
记录docker使用kong consul postgresql配置dns异常解决
docker·kong·consul
PXM的算法星球4 天前
spring gateway配合nacos实现负载均衡
spring·gateway·负载均衡
1990_super4 天前
使用ceph-deploy安装和配置RADOS Gateway (RGW)并使用S3访问集群
ceph·gateway
北极糊的狐7 天前
接口返回504 Gateway Time-out 错误,这意味着请求在网关或代理服务器等待上游服务器响应时超时。以下是可能的原因和排查建议:
数据库·gateway
sg_knight8 天前
Spring Cloud Gateway全栈实践:动态路由能力与WebFlux深度整合
java·spring boot·网关·spring·spring cloud·微服务·gateway
放纵日放纵10 天前
微服务—Gateway
微服务·架构·gateway
你我约定有三11 天前
分布式微服务--GateWay(1)
java·开发语言·分布式·微服务·架构·gateway
William一直在路上14 天前
KONG API Gateway中的核心概念
网络·gateway·kong
freesharer14 天前
kong网关集成Safeline WAF 插件
kong