2

我正在尝试将我的 Azure Functions 应用程序发布到 Kubernetes,但运行此命令时出现以下错误

func kubernetes deploy --name my-function-api --namespace default --registry mycontainerregistry/docker-azure-function --csharp

找不到项目根目录。期望在项目根目录中找到 host.json、local.settings.json 之一。`

这是我的码头文件

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS installer-env

COPY . .
RUN cd /MyFunctionApp.Api && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish *.csproj --output /home/site/wwwroot

COPY /MyFunctionApp.Api/host.json /home/site/wwwroot
COPY /MyFunctionApp.Api/local.settings.json /home/site/wwwroot

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:2.0-appservice 
FROM mcr.microsoft.com/azure-functions/dotnet:3.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

如您所见,我尝试添加以下行

COPY /MyFunctionApp.Api/host.json /home/site/wwwroot
COPY /MyFunctionApp.Api/local.settings.json /home/site/wwwroot

但这似乎也无济于事,所以不确定我需要做什么才能使其正常工作?任何帮助,将不胜感激。

4

1 回答 1

2

好的,所以想通了。Azure Functions 不读取local.settings.jsonsettings.json在容器中运行时。这些键需要设置为环境变量。

您需要将其local.settings.json放在运行命令的同一文件夹中,func kubernetes deploy这将生成一个 yaml 文件,其中包含在容器启动时传递到容器中的设置。

注意:这似乎不适用于设置CORS设置。我有一个关于AKS 集群中 Azure Functions 的 CORS 问题的新问题

于 2020-11-30T13:22:50.533 回答