【问题标题】:Azure IoT Edge API module cannot be accessed . Request timed out无法访问 Azure IoT Edge API 模块。请求超时
【发布时间】:2021-07-24 11:34:53
【问题描述】:

我正在安装在 Ubuntu hyper-v VM 上的 Azure IoT Edge 运行时上实现 API。 我在 Ubuntu vm 的边缘运行时中实现并运行了一个烧瓶 API 模块。 所以我需要从主机访问这个 API,这是我在 Windows 10 上运行的本地机器。运行的 API 模块的 IP 地址是http://172.20.36.197:5000/predict

这适用于来宾(Ubuntu hyper-v VM)机器,但每次我尝试在主机中调用此调用时请求都会超时。我什至禁用了主机 VM 的防火墙。但没有运气。看来我必须从我的主机访问在 Ubuntu VM 上运行的 IoT Edge 运行时。

我只是在 docker 容器中运行相同的烧瓶 API,而不是在 IoT 边缘运行时作为边缘模块,而是在 Ubuntu Hyper-v VM 内的 docker 中运行,我可以从主机访问该 API,没有任何问题。以下是我在物联网边缘运行时运行的烧瓶 API 边缘模块的代码

import os
from azure.iot.device.aio import IoTHubModuleClient
from flask import Flask

port =int(os.environ.get("port",5000))
print("port is ",port)

# Initialize flask app
app = Flask(__name__)

# Create an endpoint
@app.route('/predict')
def predict_chiller_condition():
    print("api func called")
    predictedVal=3
    return 'predicted value is '+str(predictedVal)

if __name__ == "__main__":
    app.run(host='0.0.0.0',port=port)

【问题讨论】:

    标签: python azure-iot-hub azure-iot-edge


    【解决方案1】:

    对于任何正在努力解决这种情况的人,您应该通过在 deployment.template.json 中的 createOptions 部分添加 ExposedPorts 来公开在来宾 VM 上运行的边缘模块容器,如下所示。并且VM的IPv4地址也应该与相关端口一起使用。

            "modules": {
            "test_flask_api": {
            "version": "1.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULES.test_flask_api}",
              "createOptions": {
                "ExposedPorts": {
                  "5000/tcp": {}
                },
                "HostConfig": {
                  "PortBindings": {
                    "5000/tcp": [
                      {
                        "HostPort": "5000"
                      }
                    ]
                  }
                }
              }
            }
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多