Kong 服务和路由的添加

管理服务

这里参考DB-less-Mode,因为使用的是yaml配置文件的形式,所以所有的相关配置只需要往初始化的kong.yml文件中添加就可以了,就像nginx的配置文件

DB-less-Mode

创建服务

vim /etc/kong/kong.yml

yaml 复制代码
services:
- name: my-service  # 服务名称
  url: localhost:8801  # 这里填写backend服务地址
  tags:
   - test-service
  routes:
  - name: ngrok-mep-server  # 路由名称
    paths:
    - /test-service  # 路由后缀名称


# 下面是初始化的建议配置
 services:
 - name: example-service
   url: http://example.com
   # Entities can store tags as metadata
   tags:
   - example
   # Entities that have a foreign-key relationship can be nested:
   routes:
   - name: example-route
     paths:
     - /
   plugins:
   - name: key-auth
 - name: another-service
   url: https://example.org

检查文件

shell 复制代码
kong config -c kong.conf parse kong.yml

Response:

复制代码
parse successful

加载文件

复制代码
kong start -c kong.conf
已启动的使用
kong restart -c kong.conf

校验服务是否正常

我们可以在kong的8000端口后加上路由后缀/test-service查看服务是否正常

复制代码
curl -i localhost:8000/test-service

这里由于项目路径原因显示404,但其实后端已经收到请求了

相关推荐
流烟默2 小时前
网关 Sentinel 限流实战:API 分组、规则加载与全量匹配踩坑记
nacos·gateway·sentinel·流控规则
Joy T9 小时前
从 Nginx 到 Gateway 再到微服务:一次 AI 请求的完整链路
nginx·微服务·gateway·controller·路由转发·ai service·接口错误排查
Thomas.Sir10 小时前
第19课:Gateway过滤器、全局拦截、请求响应统一处理
spring cloud·gateway
Thomas.Sir1 天前
第18课:Gateway路由规则、内置谓词、自定义谓词实战
spring cloud·gateway
2601_962177303 天前
2026年AI API Gateway怎么选?我整理了6种方案的费用、稳定性和适用场景
网络·人工智能·深度学习·gateway
Wang's Blog4 天前
Java框架 SpringCloud 快速入门: Gateway 路由的过滤器配置
java·spring cloud·gateway
小白的码BUG之路7 天前
Docker -- 构建ruoyi-gateway镜像
docker·容器·gateway
行者游学11 天前
Kong 插件,解决2.5.1不支持原生暴露url
junit·kong
JJJennie77711 天前
MAI Gateway技术揭秘:大模型网关能做故障转移吗?从原理到落地
gateway·ai网关