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

相关推荐
tryxr3 天前
Spring Cloud Gateway
java·开发语言·数据库·网关·spring cloud·gateway
Jay Kay4 天前
SGLang Model Gateway 特性详解(Cache-Aware 之外)
gateway·sglang
专注_每天进步一点点7 天前
SLB(绑定弹性公网ip)-gateway-业务pod,gateway上出现reset by peer,业务pod上没有reset by peer
服务器·tcp/ip·gateway
mashirro12 天前
gateway服启动输出台显示
gateway
豆瓣鸡13 天前
网关、服务 userId 透传
java·微服务·gateway
Sean‘20 天前
GitLab 升级后 502:Puma 反复重启问题处理记录
docker·gateway·gitlab
Hadoop_Liang1 个月前
使用Kubernetes Gateway API实现域名访问应用
容器·kubernetes·gateway
worilb1 个月前
Spring Cloud 学习与实践(9):Gateway + JWT 统一鉴权
学习·spring cloud·gateway
Dontla1 个月前
Kong Gateway(OSS)(Open Source Software)与 Kong Gateway(Enterprise)区别
gateway·kong
yxl874646461 个月前
磐创PCTG-9013 Modbus转ProfibusDP工业协议转换器
网络·科技·物联网·gateway·信息与通信