51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

【安装部署】K8S 部署手动初始化 APISIX 路由

当使用 k8s 部署 DataEase v2 时,出现 apisix 路由初始化失败的情况时(一般是由于 k8s 节点资源不够,测试配置:3 台 4c8g 机器),可以按照如下两种方法进行处理。

1 重启 DataEase pod {#1-%E9%87%8D%E5%90%AF-dataease-pod}

重启 DataEase 会重新执行初始化 apisix,一般情况重启即可解决,如果出现重启无效的情况,可使用手动初始化的方式。

2 手动初始化 {#2-%E6%89%8B%E5%8A%A8%E5%88%9D%E5%A7%8B%E5%8C%96}

(1) 获取 DE_APISIX_KEY

进入 DataEase pod 中,获取 /opt/apps/config/application.yml 文件中的 key,具体如下图

(2) APISIX 初始化

进入到 APISIX pod 中,将如下所有命令的 $DE_APISIX_KEY 替换成上一步获取到的 key, 然后依次执行如下六个命令。

#1.create upstream core_api
curl http://127.0.0.1:9180/apisix/admin/upstreams/1 -X PUT -H "X-API-KEY: $DE_APISIX_KEY" -d '
{
  "nodes": [
    {
      "host": "dataease",
      "port": 8100,
      "weight": 1
    }
  ],
  "timeout": {
    "connect": 6,
    "send": 10,
    "read": 60
  },
  "type": "roundrobin",
  "scheme": "http",
  "pass_host": "pass",
  "name": "core_api",
  "desc": "dataease core service",
  "keepalive_pool": {
    "idle_timeout": 60,
    "requests": 1000,
    "size": 320
  }
}'

#2.create forward auth route
curl http://127.0.0.1:9180/apisix/admin/routes -X POST -H "X-API-KEY: $DE_APISIX_KEY" -d '
{

"uri": "/de2api/apisix/check",
"name": "auth_check",
"methods": \[
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
\],
"upstream_id": "1",
"status": 1
}'


#3.create auth_service
curl http://127.0.0.1:9180/apisix/admin/services/10 -X PUT -H "X-API-KEY: $DE_APISIX_KEY" -d '
{
"name": "auth_service",
"desc": "dataease auth service",
"upstream_id": "1",
"plugins": {
"forward-auth": {
"_meta": {
"disable": false
},
"client_headers": \[
"Location",
"DE-GATEWAY-FLAG",
"DE-FORBIDDEN-FLAG"
\],
"request_headers": \[
"X-DE-TOKEN",
"X-DE-LINK-TOKEN",
"X-EMBEDDED-TOKEN",
"X-DE-ASK-TOKEN",
"Content-Type",
"Origin"
\],
"request_method": "POST",
"upstream_headers": \[
"X-User-ID",
"X-DE-REFRESH-TOKEN",
"X-DE-TOKEN"
\],
"uri": "http://127.0.0.1:9080/de2api/apisix/check"
}
}
}'


#4.create static resource route
curl http://127.0.0.1:9180/apisix/admin/routes -X POST -H "X-API-KEY: $DE_APISIX_KEY" -d '
{
"uris": \[
"/js/",
"/assets/",
"/vite.svg"
\],
"name": "global_static",
"priority": 1,
"methods": \[
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
\],
"upstream_id": "1",
"status": 1
}'


#5.create default index route
curl http://127.0.0.1:9180/apisix/admin/routes -X POST -H "X-API-KEY: $DE_APISIX_KEY" -d '
{
"uri": "/\*",
"name": "default_index",
"priority": 100,
"methods": \[
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
\],
"vars": \[
\[
"http_out_auth_platform",
"!",
"IN",
\[
"ldap",
"oidc",
"cas"
\]
\]
\],
"upstream_id": "1",
"enable_websocket": true,
"status": 1
}'

`#6.create default api route
curl http://127.0.0.1:9180/apisix/admin/routes -X POST -H "X-API-KEY: $DE_APISIX_KEY" -d '
{
"uri": "/de2api/*",
"name": "default_api",
"priority": 6,
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
],
"vars": [
[
"http_out_auth_platform",
"!",
"IN",
[
"ldap",
"oidc",
"cas"
]
]
],
"service_id": "10",
"status": 1
}'`

(3) 查看 dashboard 是否成功

进入到 APISIX Dashboard 中,查看路由,上游,服务,一共六个配置是否都初始化成功。

赞(0)
未经允许不得转载:工具盒子 » 【安装部署】K8S 部署手动初始化 APISIX 路由