Azure Functions Kubernetes cannot find local.settings.json

11/28/2020

I am trying to publish my Azure Functions App to Kubernetes but I am getting the following error when I run this command

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.`

This is my docker file

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"]

As you can see I have tried adding the following lines

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

But that does not seem to help either, so not sure what I need to do to get this working? Any help would be appreciated.

-- Lenny D
azure-functions
c#
docker
keda
kubernetes

1 Answer

11/30/2020

Ok so figured this out. Azure Functions does not read local.settings.json or settings.json when running in a container. These keys need to be set as environment variables.

You need to have the local.settings.json in the the same folder that you run the func kubernetes deploy command from and that will generate a yaml file with the settings that get passed into the container when it is started.

NB: this does not seem to work with setting CORS settings. I have a new question for that here https://stackoverflow.com/questions/65074215/cors-issue-with-azure-functions-inside-aks-cluster

-- Lenny D
Source: StackOverflow