【发布时间】:2019-07-09 21:10:49
【问题描述】:
我正在尝试编写 API 并在 Azure Function 应用程序上发布和运行。在函数中我需要从 kubectl 中读取。 在 localhost 上读取 kubectl 和配置可以正常工作。 但是当我发布到 azure 函数应用程序时,它返回错误消息:“异常:OSError:[Errno 8] Exec 格式错误:'./kubectl'”。
我在 Mac 设备上使用 Python 在 Azure 中创建 HTTP 触发函数。而 Azure 服务计划是 LinusDynamicPlan。我使用的 kubectl 是一个 mac 二进制文件。
读取 kubectl 的代码:
deployments = subprocess.check_output(["./kubectl", "get", "deployments", cluster_config_name])
我可以在本地主机上成功运行脚本。但不在 Azure 函数应用中。 我在 Azure 中收到的错误消息:
2019-07-09T07:37:38.168 [Error] Executed 'Functions.nc6v3_usage' (Failed, Id=71d76d36-95ab-4bd6-9656-5578141c4c3f)
Result: Failure
Exception: OSError: [Errno 8] Exec format error: './kubectl'
Stack: File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 300, in _handle__invocation_request
self.__run_sync_func, invocation_id, fi.func, args)
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 389, in __run_sync_func
return func(**params)
File "/home/site/wwwroot/nc6v3_usage/__init__.py", line 18, in main
deployments = subprocess.check_output(["./kubectl", "get", "deployments", cluster_config_name])
File "/usr/local/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/local/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
【问题讨论】: