【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

相关推荐
小毅&Nora10 小时前
【后端】【诡秘架构】 序列7:魔术师 - API网关与协议转换的艺术:用Kong编织系统的幻象
架构·kong
库库林_沙琪马15 小时前
4、Gateway
gateway
全靠bug跑15 小时前
Spring Cloud Gateway 实战:统一鉴权与用户信息全链路透传
java·开发语言·gateway·拦截器
骚戴2 天前
架构设计之道:构建高可用的大语言模型(LLM) Enterprise GenAI Gateway
java·人工智能·架构·大模型·gateway·api
Maiko Star3 天前
Gateway网关拦截自定义header & 用户上下文打通实战
gateway·threadlocal
skywalk81637 天前
LLM API Gateway:使用Comate Spec Mode创建大模型调用中转服务器
服务器·人工智能·gateway·comate
2401_860494707 天前
如何在React Native中,开发一个类似于鸿蒙组件(Hong Kong component)的NoticeBar(通知栏)组件呢?
javascript·react native·react.js·ecmascript·kong·harmonyos
我是小妖怪,潇洒又自在7 天前
springcloud alibaba(七)Gateway--服务网关
spring·spring cloud·gateway
boy快快长大10 天前
【Spring Cloud Alibaba】Gateway(一)
数据库·gateway