【Azure APIM】解决APIM Self-hosted Gateway在AKS上,最开始访问时候遇见的404问题

问题描述

根据APIM官方文档,创建Self-hosted 网关在AKS中( 使用 YAML 将自承载网关部署到 Kubernetes :https://docs.azure.cn/zh-cn/api-management/how-to-deploy-self-hosted-gateway-kubernetes),但是访问AKS中Services的Endpoint,得到的确实 404页面。

{
    "statusCode": 404,
    "message": "Resource not found"
}

访问截图:

查看AKS POD的日志,也是显示404 错误

PS C:\> kubectl get pods
NAME                                                    READY   STATUS      RESTARTS   AGE
lbapimselftest01-77f5b8db75-7skq4                       1/1     Running     0          5h24m
node-debugger-aks-agentpool-36712949-vmss000000-dlf6h   1/1     Running     0          4h57m
node-debugger-aks-agentpool-36712949-vmss000000-kv2ln   0/1     Completed   0          5h9m
sputnik-metrics-965c64dbc-zt94k                         2/2     Running     0          5h48m
PS C:\> kubectl logs lbapimselftest01-77f5b8db75-7skq4

... ...

[Info] 2023-10-16T11:26:38.139 [GatewayLogs], isRequestSuccess: False, totalTime: 0, category: GatewayLogs, callerIpAddress: 18.20.91.9, timeGenerated: 2023-10-16T11:26:38.139, region: ChinaNorth3, correlationId: 12909eb4-8dc4-438b-b27d-c667aca4852a, method: GET, url: http://14.6.8.17/echo/resource?param1=sample&param2=test, responseCode: 404, responseSize: 198, cache: none, clientProtocol: HTTP/1.1, lastError: {
"source": "configuration",
"reason": "OperationNotFound",
"message": "Unable to match incoming request to an operation.",
"section": "backend"
}, correlationId: 12909eb4-8dc4-438b-b27d-c667aca4852a
[Info] 2023-10-16T11:26:41.435 [GatewayLogs], isRequestSuccess: False, totalTime: 0, category: GatewayLogs, callerIpAddress: 18.20.91.9, timeGenerated: 2023-10-16T11:26:41.435, region: ChinaNorth3, correlationId: cd4ad591-c3fa-4241-8dca-e10370c8d776, method: GET, url: http://14.6.8.17/, responseCode: 404, responseSize: 198, cache: none, clientProtocol: HTTP/1.1, lastError: {
"source": "configuration",
"reason": "OperationNotFound",
"message": "Unable to match incoming request to an operation.",
"section": "backend"
}, correlationId: cd4ad591-c3fa-4241-8dca-e10370c8d776

 

 

问题解答

首先,需要查看APIM Self-hosted Gateway是否有关联到被访问的API,测试中所使用的是echo API。

再次访问API接口:http://xxx.xxx.xxx.xxx/echo/resource?param1=sample&param2=test, 依旧是404,就需要查看是否是API的设定中是否允许HTTP访问,

所以,判断这是因为APIs的设置中,只允许了HTTPS访问。当修改为HTTP(S)后,HTTP/HTTPS都可以访问成功。解决了最开始访问出现404的问题。

总结,需要检查APIM中APIs的两个设定:

1)是否为此API添加到 self-hosted gateway 

2)访问中配置的是否只能HTTP (HTTPS) 访问 

 

参考资料

使用 YAML 将自承载网关部署到 Kubernetes : https://docs.azure.cn/zh-cn/api-management/how-to-deploy-self-hosted-gateway-kubernetes

Azure API Management Self-hosted Gateway - SOAP API not working : https://learn.microsoft.com/en-us/answers/questions/1152222/azure-api-management-self-hosted-gateway-soap-api?page=1

 

 

posted @ 2023-10-16 19:54  路边两盏灯  阅读(44)  评论(0编辑  收藏  举报