【工作记录】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 内置插件使用的相关案例。

相关推荐
耳东哇14 小时前
sentinel docker gateway k8s 集群 主从
docker·gateway·sentinel
龙茶清欢1 天前
2、Nginx 与 Spring Cloud Gateway 详细对比:定位、场景与分工
java·运维·spring boot·nginx·spring cloud·gateway
龙茶清欢2 天前
在 Spring Cloud Gateway 中实现跨域(CORS)的两种主要方式
java·spring boot·spring cloud·微服务·gateway
William一直在路上2 天前
Kong Gateway 实操实例:代理上游服务并配置限流插件
gateway·kong
龙茶清欢3 天前
4、除了常见的 services(业务微服务)和 gateway(API 网关)模块外,还必须建立一系列支撑性、平台级、基础设施类模块
微服务·架构·gateway
debug 小菜鸟5 天前
Python + Flask + API Gateway + Lambda + EKS 实战
python·flask·gateway
Li zlun6 天前
Kubernetes 进阶实战:CRD、Gateway API 与优先级调度
java·kubernetes·gateway
zzz.106 天前
k8s中的Gateway API 和istio
云原生·kubernetes·gateway·istio
疯狂的维修16 天前
关于Gateway configration studio软件配置网关
网络协议·c#·自动化·gateway