【工作记录】Kong Gateway 入门篇之部署及简单测试

Kong Gateway部署

Kong Gateway 可以通过多种方式部署,包括 Docker、Kubernetes、以及直接安装在操作系统上。以下是常见的部署方法:

使用 Docker 部署
  1. 安装 Docker 和 Docker Compose。
  2. 创建一个 docker-compose.yml 文件,内容如下:
yaml 复制代码
version: '3.7'

services:
  kong:
    image: kong:latest
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-database
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: kong
      KONG_PG_DATABASE: kong
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8443:8443"
      - "8444:8444"
    depends_on:
      - kong-database

  kong-database:
    image: postgres:9.6
    environment:
      POSTGRES_USER: kong
      POSTGRES_PASSWORD: kong
      POSTGRES_DB: kong
    ports:
      - "5432:5432"
  1. 启动服务:
bash 复制代码
docker-compose up -d
使用 Kubernetes 部署
  1. 安装 Kubernetes 和 Helm。
  2. 添加 Kong Helm 仓库:
bash 复制代码
helm repo add kong https://charts.konghq.com
helm repo update
  1. 安装 Kong:
bash 复制代码
helm install my-kong kong/kong
直接安装在操作系统上
  1. 下载并安装 Kong:
bash 复制代码
wget https://bintray.com/kong/kong-community-edition-deb/download_file?file_path=dists/kong-community-edition-2.4.1.$(lsb_release -cs).all.deb
sudo dpkg -i kong-community-edition-2.4.1.*.deb
  1. 配置 Kong 数据库:
bash 复制代码
kong migrations bootstrap
  1. 启动 Kong:
bash 复制代码
kong start

测试 Kong Gateway

部署完成后,可以通过以下步骤测试 Kong Gateway 是否正常工作。

检查 Kong 状态
bash 复制代码
curl -i http://localhost:8001/

如果返回 200 状态码,说明 Kong 已成功启动。

添加一个服务
  1. 创建一个服务:
bash 复制代码
curl -i -X POST \
  --url http://localhost:8001/services/ \
  --data 'name=example-service' \
  --data 'url=http://mockbin.org'
  1. 为服务添加路由:
bash 复制代码
curl -i -X POST \
  --url http://localhost:8001/services/example-service/routes \
  --data 'hosts[]=example.com'
测试路由
bash 复制代码
curl -i -X GET \
  --url http://localhost:8000/ \
  --header 'Host: example.com'

如果返回 200 状态码,说明路由配置成功。

使用插件
  1. 安装并启用一个插件,例如 key-auth
bash 复制代码
curl -i -X POST \
  --url http://localhost:8001/services/example-service/plugins \
  --data 'name=key-auth'
  1. 测试插件:
bash 复制代码
curl -i -X GET \
  --url http://localhost:8000/ \
  --header 'Host: example.com'

如果返回 401 状态码,说明插件已成功启用。

通过以上步骤,可以完成 Kong Gateway 的部署与基本测试。

总结

本文介绍了kong gateway的不同部署方式及简单测试的情况。

后面会继续介绍关于kong gateway 内置插件使用的相关案例。

相关推荐
2601_9491942615 小时前
Gateway Timeout504 网关超时的完美解决方法
gateway
码点滴2 天前
私有 Gateway 接入企业 IM:从消息路由到多租户隔离——Hermes Agent 工程实战
人工智能·架构·gateway·prompt·智能体·hermes
代码写到35岁2 天前
Gateway+OpenFeign 踩坑总结
gateway
invicinble2 天前
对于gateway信息量沉淀
gateway
郝开3 天前
Spring Cloud Gateway 3.5.14 使用手册
java·数据库·spring boot·gateway
Ribou4 天前
Kubernetes v1.35.2 基于 Cilium Gateway API 的服务访问架构
架构·kubernetes·gateway
huipeng9265 天前
GateWay使用详解
java·spring boot·spring cloud·微服务·gateway
随风,奔跑8 天前
Spring Cloud Alibaba(四)---Spring Cloud Gateway
后端·spring·gateway
jiayong238 天前
Hermes Agent 的 Skills、Plugins、Gateway 深度解析
ai·gateway·agent·hermes agent·hermes
鬼蛟9 天前
Gateway
gateway