azure - 异常: OSError: [Errno 8] Exec format error: './kubectl' when publish to Azure Function App

标签 azure exec kubectl

我正在尝试编写一个 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/

相关文章:

azure - AKS。无法从 acr 中提取图像

azure - 为什么 Azure API 不列出名为/folder/folder/file 的 blob?

Azure 安全中心 ARM 模板为所有资源启用标准计划

PHP passthru() 返回 "sh: 1: svn: not found "错误

python - 在 Python 中使用 os.execvp

logging - Kubernetes 的 Pod 日志文件在哪里?

python - Azure Web作业 : Force stop if running longer than X mins

linux - 使用现有终端的参数打开一个新终端

docker - kubectl不在一个节点上寻找本地镜像,但在另一节点上运行良好

kubectl - 如何将 github secret 变量通过管道传输到文件中