【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

相关推荐
lhrimperial1 天前
深入浅出Spring Cloud Gateway:从理论到企业级实践(一)
spring cloud·微服务·系统架构·gateway
lhrimperial1 天前
深入浅出Spring Cloud Gateway:从理论到企业级实践(二)
spring cloud·微服务·系统架构·gateway
ghostwritten2 天前
云原生流量治理新标准:Kubernetes Gateway API 部署实践指南
云原生·kubernetes·gateway
齐 飞2 天前
Spring Cloud Alibaba快速入门-Gateway
spring cloud·微服务·gateway
Linux运维技术栈2 天前
Gravitee Kafka Gateway 规范部署:HTTP API化封装与安全隔离实践
http·kafka·gateway
trayvontang4 天前
Spring Gateway核心概念、流程及原理
spring·gateway·spring gateway
trayvontang4 天前
Spring Gateway常用过滤器(限流、熔断等)
spring·gateway·spring gateway·gateway常用过滤器
Hello.Reader6 天前
Flink SQL Gateway 把 Flink SQL 变成“多客户端并发可用”的统一服务入口
sql·flink·gateway
ygqygq28 天前
Kubernetes Gateway API 与 Envoy Gateway 部署使用指南
kubernetes·gateway·envoy·ingress
weixin_439706258 天前
spring boot+nacos+gateway+sentinel的简单例子
spring boot·gateway·sentinel