Skip to content

wssaidong/higress-admin-sdk-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Higress Admin SDK Demo

基于 Spring Boot 2.7.18 和 Higress Admin SDK 的网关配置管理示例项目。

技术栈

  • Java 17
  • Spring Boot 2.7.18
  • Higress Admin SDK 0.0.2
  • Hutool 5.8.34

项目结构

higress-admin-sdk-demo/
├── src/
│   ├── main/
│   │   ├── java/com/example/higress/
│   │   │   ├── config/              # 配置类
│   │   │   │   ├── HigressProperties.java
│   │   │   │   └── HigressServiceProviderConfig.java
│   │   │   ├── controller/          # REST 控制器
│   │   │   │   └── HigressController.java
│   │   │   ├── service/             # 服务类
│   │   │   │   ├── DomainManagementService.java
│   │   │   │   ├── RouteManagementService.java
│   │   │   │   └── MultiInstanceService.java
│   │   │   └── HigressAdminDemoApplication.java
│   │   └── resources/
│   │       └── application.yml
│   └── test/
└── pom.xml

功能特性

1. 域名管理

  • 添加域名
  • 删除域名
  • 获取域名列表
  • 获取单个域名
  • 更新域名

2. 路由管理

  • 添加路由
  • 删除路由
  • 获取路由列表
  • 获取单个路由
  • 更新路由

3. 多实例管理

  • 管理多个 Higress 实例
  • 向指定实例添加域名/路由
  • 获取指定实例的域名/路由列表
  • 跨实例配置同步

配置说明

编辑 application.yml 文件配置 Higress 实例:

higress:
  default:
    kube-config-path: ${HOME}/.kube/config
    namespace: higress-system
  instances:
    prod:
      kube-config-path: ${HOME}/.kube/config
      namespace: higress-prod
    test:
      kube-config-path: ${HOME}/.kube/config
      namespace: higress-test

API 接口

域名管理

方法 路径 说明
POST /api/higress/domains 添加域名
GET /api/higress/domains 获取域名列表
GET /api/higress/domains/{domainName} 获取单个域名
PUT /api/higress/domains/{domainName} 更新域名
DELETE /api/higress/domains/{domainName} 删除域名

路由管理

方法 路径 说明
POST /api/higress/routes 添加路由
GET /api/higress/routes 获取路由列表
GET /api/higress/routes/{routeName} 获取单个路由
PUT /api/higress/routes/{routeName} 更新路由
DELETE /api/higress/routes/{routeName} 删除路由

多实例管理

方法 路径 说明
GET /api/higress/instances 获取所有实例
POST /api/higress/instances/{instanceName}/domains 向指定实例添加域名
POST /api/higress/instances/{instanceName}/routes 向指定实例添加路由
GET /api/higress/instances/{instanceName}/domains 获取指定实例的域名列表
GET /api/higress/instances/{instanceName}/routes 获取指定实例的路由列表
POST /api/higress/sync/domains 同步域名配置
POST /api/higress/sync/routes 同步路由配置

使用示例

添加域名

curl -X POST "http://localhost:8080/api/higress/domains?domainName=www.example.com&enableHttps=false"

添加路由

curl -X POST "http://localhost:8080/api/higress/routes?routeName=demo-route&domains=www.example.com&path=/&serviceName=demo-service.default.svc.cluster.local:8080"

向指定实例添加路由

curl -X POST "http://localhost:8080/api/higress/instances/prod/routes?routeName=demo-route&domains=www.example.com&path=/&serviceName=demo-service.default.svc.cluster.local:8080"

同步配置

# 同步域名
curl -X POST "http://localhost:8080/api/higress/sync/domains?sourceInstance=test&targetInstance=prod"

# 同步路由
curl -X POST "http://localhost:8080/api/higress/sync/routes?sourceInstance=test&targetInstance=prod"

运行项目

mvn spring-boot:run

测试

mvn test

环境要求

  • JDK 17+
  • Maven 3.8+
  • Kubernetes 集群(运行时需要)
  • Higress 网关(运行时需要)

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages