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

相关推荐
摘星编程4 天前
Nginx 502 Bad Gateway:从 upstream 日志到 FastCGI 超时复盘
网络·nginx·gateway·php-fpm·fastcgi
网硕互联的小客服4 天前
504 Gateway Timeout:服务器作为网关或代理时未能及时获得响应如何处理?
运维·服务器·gateway
Pierre_5 天前
通过SpringCloud Gateway实现API接口镜像请求(陪跑)网关功能
spring·spring cloud·gateway
kk在加油6 天前
智能门卫:Gateway
gateway
小安同学iter7 天前
Spring Cloud Gateway 网关(五)
java·开发语言·spring cloud·微服务·gateway
JAVA学习通7 天前
Spring Cloud ------ Gateway
java·spring cloud·gateway
weixin_449568709 天前
访问Nginx 前端页面,接口报502 Bad Gateway
前端·nginx·gateway
yangmf204013 天前
LDAP 认证系列(四):Gateway LDAP 认证
大数据·elasticsearch·搜索引擎·gateway·ldap
银迢迢14 天前
SpringCloud微服务技术自用笔记
java·spring cloud·微服务·gateway·sentinel
孤狼程序员18 天前
【Spring Cloud 微服务】2.守护神网关Gateway
spring cloud·微服务·gateway