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

相关推荐
唐僧洗头爱飘柔95271 天前
【SpringCloud(6)】Gateway路由网关;zuul路由;gateway实现原理和架构概念;gateway工作流程;静态转发配置
spring·spring cloud·架构·gateway·请求转发·服务降级·服务雪崩
xrkhy2 天前
微服务之Gateway网关(1)
微服务·架构·gateway
无名客07 天前
SpringCloud中的网关(Gateway)的作用是什么?
spring·spring cloud·gateway
smilecold8 天前
SpringCloud 入门 - Gateway 网关与 OpenFeign 服务调用
spring cloud·gateway
INFINI Labs10 天前
Elasticsearch 备份:方案篇
大数据·elasticsearch·搜索引擎·gateway·snapshot·backup·ccr
纤瘦的鲸鱼10 天前
Spring Gateway 全面解析:从入门到进阶实践
java·spring·gateway
无名小卒202212 天前
{人工智能}未来十年改变世界的核心技术驱动力
kong
INFINI Labs13 天前
如何使用 INFINI Gateway 对比 ES 索引数据
大数据·elasticsearch·gateway·easysearch
m0_6515939114 天前
位置透明性、Spring Cloud Gateway与reactor响应式编程的关系
java·spring cloud·系统架构·gateway
nvd1115 天前
使用gateway api来实现GKE 的pods 从外部访问
gateway·googlecloud