基于 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
- 添加域名
- 删除域名
- 获取域名列表
- 获取单个域名
- 更新域名
- 添加路由
- 删除路由
- 获取路由列表
- 获取单个路由
- 更新路由
- 管理多个 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
| 方法 |
路径 |
说明 |
| 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"
- JDK 17+
- Maven 3.8+
- Kubernetes 集群(运行时需要)
- Higress 网关(运行时需要)