使用 postgresql 安装 kong 并使用 REST 添加服务 API
Installing kong with postgresql and add service with REST API
我目前在使用 postgresql 安装 kong 时遇到问题
并通过 REST 调用将服务添加到 kong 管理服务器。
我的安装命令如下:
helm install kong kong/kong -n kong \
--set ingressController.installCRDs=false \
--set admin.enabled=true \
--set admin.http.enabled=true \
--set postgresql.enabled=true \
--set postgresql.auth.username=kong \
--set postgresql.auth.database=kong \
--set postgresql.service.ports.postgresql=5432 \
--set postgresql.image.tag=13.6.0-debian-10-r52 \
--set migrations.init=false \
--set migrations.preUpgrade=false \
--set migrations.postUpgrade=false
安装正常
注册服务后,会出现以下消息。
别着急,LoadBalance pending 稍后会修改为NodePort!
root@nlu-framework-master-1:~# k get all -n kong
NAME READY STATUS RESTARTS AGE
pod/kong-kong-5b685cd4b9-t95mx 2/2 Running 1 3m22s
pod/kong-postgresql-0 1/1 Running 1 3m22s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kong-kong-admin NodePort 10.233.7.63 <none> 8001:31422/TCP,8444:31776/TCP 3m22s
service/kong-kong-proxy LoadBalancer 10.233.0.19 <pending> 80:30511/TCP,443:30358/TCP 3m22s
service/kong-postgresql ClusterIP 10.233.42.35 <none> 5432/TCP 3m22s
service/kong-postgresql-headless ClusterIP None <none> 5432/TCP 3m22s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kong-kong 1/1 1 1 3m22s
NAME DESIRED CURRENT READY AGE
replicaset.apps/kong-kong-5b685cd4b9 1 1 1 3m22s
NAME READY AGE
statefulset.apps/kong-postgresql 1/1 3m22s
我的添加服务命令如下:
curl -X POST http://10.233.7.63:8001/services \
-H 'Content-Type: application/json' \
-d '{"name":"k8s-api","url":"https://192.168.0.50:6443/api/v1/"}'
添加服务结果消息如下:
{"code":12,"message":"cannot create 'services' entities when not using a database","name":"operation unsupported"}
请任何人帮助我
我自己解决问题
- postgresql version 14 或更高版本似乎有错误,安装 helm chart cetic/postgresql。
helm chart cetic/postgresql 的 postgresql 版本 11.5
https://artifacthub.io/packages/helm/cetic/postgresql
helm install postgres cetic/postgresql -n kong \
--set postgresql.username=kong \
--set postgresql.password=kong \
--set postgresql.database=kong \
--set postgresql.port=5432
- 使用外部 postgresql 安装 bitnami/kong
helm install kong -n kong bitnami/kong \
--set postgresql.enabled=false \
--set postgresql.external.host=postgres-postgresql \
--set postgresql.external.user=kong \
--set postgresql.external.password=kong \
--set postgresql.external.database=kong
k get all -n kong
NAME READY STATUS RESTARTS AGE
pod/kong-9688f7f55-42cfm 2/2 Running 3 2m15s
pod/kong-9688f7f55-5ntvw 2/2 Running 3 2m15s
pod/postgres-postgresql-0 1/1 Running 0 4m54s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kong ClusterIP 10.233.39.160 <none> 80/TCP,443/TCP 2m15s
service/postgres-postgresql ClusterIP 10.233.23.169 <none> 5432/TCP 4m54s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kong 2/2 2 2 2m15s
NAME DESIRED CURRENT READY AGE
replicaset.apps/kong-9688f7f55 2 2 2 2m15s
NAME READY AGE
statefulset.apps/postgres-postgresql 1/1 4m54s
- 将服务类型更改为 nodeport 并添加管理服务
k edit service/kong -n kong
- name: http-admin
port: 8001
protocol: TCP
targetPort: http-admin
- name: https-admin
port: 8444
protocol: TCP
targetPort: https-admin
- 使用管理服务 clusterIP 测试添加服务。
curl -X POST http://10.233.39.160:8001/services \
> -H 'Content-Type: application/json' \
> -d '{"name":"k8s-api","url":"https://192.168.0.50:6443/api/v1/"}'
- 检查服务是否添加成功
curl http://10.233.39.160:8001/services | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 401 100 401 0 0 97k 0 --:--:-- --:--:-- --:--:-- 97k
{
"next": null,
"data": [
{
"id": "5cc7f7ce-3494-44fa-b76c-47795192f541",
"host": "192.168.0.50",
"path": "/api/v1/",
"protocol": "https",
"retries": 5,
"ca_certificates": null,
"write_timeout": 60000,
"port": 6443,
"tags": null,
"name": "k8s-api",
"tls_verify": null,
"client_certificate": null,
"tls_verify_depth": null,
"connect_timeout": 60000,
"enabled": true,
"created_at": 1649513267,
"updated_at": 1649513267,
"read_timeout": 60000
}
]
}
我目前在使用 postgresql 安装 kong 时遇到问题 并通过 REST 调用将服务添加到 kong 管理服务器。
我的安装命令如下:
helm install kong kong/kong -n kong \
--set ingressController.installCRDs=false \
--set admin.enabled=true \
--set admin.http.enabled=true \
--set postgresql.enabled=true \
--set postgresql.auth.username=kong \
--set postgresql.auth.database=kong \
--set postgresql.service.ports.postgresql=5432 \
--set postgresql.image.tag=13.6.0-debian-10-r52 \
--set migrations.init=false \
--set migrations.preUpgrade=false \
--set migrations.postUpgrade=false
安装正常 注册服务后,会出现以下消息。 别着急,LoadBalance pending 稍后会修改为NodePort!
root@nlu-framework-master-1:~# k get all -n kong
NAME READY STATUS RESTARTS AGE
pod/kong-kong-5b685cd4b9-t95mx 2/2 Running 1 3m22s
pod/kong-postgresql-0 1/1 Running 1 3m22s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kong-kong-admin NodePort 10.233.7.63 <none> 8001:31422/TCP,8444:31776/TCP 3m22s
service/kong-kong-proxy LoadBalancer 10.233.0.19 <pending> 80:30511/TCP,443:30358/TCP 3m22s
service/kong-postgresql ClusterIP 10.233.42.35 <none> 5432/TCP 3m22s
service/kong-postgresql-headless ClusterIP None <none> 5432/TCP 3m22s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kong-kong 1/1 1 1 3m22s
NAME DESIRED CURRENT READY AGE
replicaset.apps/kong-kong-5b685cd4b9 1 1 1 3m22s
NAME READY AGE
statefulset.apps/kong-postgresql 1/1 3m22s
我的添加服务命令如下:
curl -X POST http://10.233.7.63:8001/services \
-H 'Content-Type: application/json' \
-d '{"name":"k8s-api","url":"https://192.168.0.50:6443/api/v1/"}'
添加服务结果消息如下:
{"code":12,"message":"cannot create 'services' entities when not using a database","name":"operation unsupported"}
请任何人帮助我
我自己解决问题
- postgresql version 14 或更高版本似乎有错误,安装 helm chart cetic/postgresql。 helm chart cetic/postgresql 的 postgresql 版本 11.5 https://artifacthub.io/packages/helm/cetic/postgresql
helm install postgres cetic/postgresql -n kong \
--set postgresql.username=kong \
--set postgresql.password=kong \
--set postgresql.database=kong \
--set postgresql.port=5432
- 使用外部 postgresql 安装 bitnami/kong
helm install kong -n kong bitnami/kong \
--set postgresql.enabled=false \
--set postgresql.external.host=postgres-postgresql \
--set postgresql.external.user=kong \
--set postgresql.external.password=kong \
--set postgresql.external.database=kong
k get all -n kong
NAME READY STATUS RESTARTS AGE
pod/kong-9688f7f55-42cfm 2/2 Running 3 2m15s
pod/kong-9688f7f55-5ntvw 2/2 Running 3 2m15s
pod/postgres-postgresql-0 1/1 Running 0 4m54s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kong ClusterIP 10.233.39.160 <none> 80/TCP,443/TCP 2m15s
service/postgres-postgresql ClusterIP 10.233.23.169 <none> 5432/TCP 4m54s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/kong 2/2 2 2 2m15s
NAME DESIRED CURRENT READY AGE
replicaset.apps/kong-9688f7f55 2 2 2 2m15s
NAME READY AGE
statefulset.apps/postgres-postgresql 1/1 4m54s
- 将服务类型更改为 nodeport 并添加管理服务
k edit service/kong -n kong
- name: http-admin
port: 8001
protocol: TCP
targetPort: http-admin
- name: https-admin
port: 8444
protocol: TCP
targetPort: https-admin
- 使用管理服务 clusterIP 测试添加服务。
curl -X POST http://10.233.39.160:8001/services \
> -H 'Content-Type: application/json' \
> -d '{"name":"k8s-api","url":"https://192.168.0.50:6443/api/v1/"}'
- 检查服务是否添加成功
curl http://10.233.39.160:8001/services | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 401 100 401 0 0 97k 0 --:--:-- --:--:-- --:--:-- 97k
{
"next": null,
"data": [
{
"id": "5cc7f7ce-3494-44fa-b76c-47795192f541",
"host": "192.168.0.50",
"path": "/api/v1/",
"protocol": "https",
"retries": 5,
"ca_certificates": null,
"write_timeout": 60000,
"port": 6443,
"tags": null,
"name": "k8s-api",
"tls_verify": null,
"client_certificate": null,
"tls_verify_depth": null,
"connect_timeout": 60000,
"enabled": true,
"created_at": 1649513267,
"updated_at": 1649513267,
"read_timeout": 60000
}
]
}