我正在尝试编写一个 API 并在 Azure Function 应用程序上发布和运行。在函数中我需要从 kubectl 读取内容。 读取 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)
最佳答案
The kubectl I'm using is a mac binary.
如果我没有正确理解你的意思,请纠正我。您是否在 Azure 实例的 Linux 系统上使用 mac 二进制文件?如果是这样,你就是做不到,Mac =/= Linux。
尝试按照 this instruction 在您的 Azure 实例上安装 kubectl
由官方 Kubernetes 文档提供,然后将为您的系统安装的 kubectl 二进制文件的完整路径提供给您的脚本。如果您按照上述说明操作,它将是 /usr/local/bin/kubectl
。
关于azure - 异常: OSError: [Errno 8] Exec format error: './kubectl' when publish to Azure Function App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56947619/