Azure Functions Kubernetes 找不到 local.settings.json

Azure Functions Kubernetes cannot find local.settings.json

我正在尝试将我的 Azure Functions 应用程序发布到 Kubernetes,但是当我 运行 此命令

时出现以下错误

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

Unable to find project root. Expecting to find one of host.json, local.settings.json in project root.`

这是我的 docker 文件

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

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

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

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

注意:这似乎不适用于 CORS 设置。我在这里有一个新问题 CORS Issue with Azure Functions inside AKS Cluster