azure-functions-core-tools
azure-functions-core-tools copied to clipboard
Azure Functions Core Tools v4 unable deploy to Kubernetes
G:\Projects\funapp2>func --version
4.0.3928
G:\Projects\funapp2>dotnet --version
6.0.100
Here are the steps to reproduce the problem.
mkdir funapp2 && cd funapp2
func init --worker-runtime dotnetIsolated --docker
func new -t "HttpTrigger" -n "Login" -a "anonymous"
Modify the Dockerfile
file as below:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /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-isolated:3.0-dotnet-isolated5.0-appservice
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:3.0-dotnet-isolated5.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
Build & Push image
docker build -t willh/funapp2:latest .
docker push willh/funapp2:latest
Deploy my function app with --dry-run
func kubernetes deploy --name funapp2 --service-type NodePort --image-name willh/funapp2 --dry-run
There is only Secret been created.
data:
AzureWebJobsStorage: VXNlRGV2ZWxvcG1lbnRTdG9yYWdlPXRydWU=
FUNCTIONS_WORKER_RUNTIME: ZG90bmV0LWlzb2xhdGVk
apiVersion: v1
kind: Secret
metadata:
name: funapp2
---
Where is the other YAML of the deployment?
upvote, i am encountering the same bug
@MACEL94 It seems nobody watching this repo. I reported a few issues that is been stalled for more than 1 month.
I'm intending on deploying a set of .NET 6 functions to a kubernetes cluster early next year. Would be great to have this fixed by then!
Just confirming still an issue and now an issue for us. net6 & func --version 4.0.3971 We are deploying secrets independently before running func kubernetes deploy, so different to OP. I'm not expecting any secrets yaml in the output. --dry-run > output.yaml generates completely empty output file
I created a PR to resolve this issue inside the functions tooling: #3000
In the meantime, if you want an immediate fix on your project's side, I also created a helper program that does that. It is published as a NuGet package Az.Functions.MetadataToJson (repo on GitHub)
Just add a reference to it in your project file and it should make the func kubernetes deploy
work as expected.
@
G:\Projects\funapp2>func --version 4.0.3928 G:\Projects\funapp2>dotnet --version 6.0.100
Here are the steps to reproduce the problem.
mkdir funapp2 && cd funapp2 func init --worker-runtime dotnetIsolated --docker func new -t "HttpTrigger" -n "Login" -a "anonymous"
Modify the
Dockerfile
file as below:FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env COPY . /src/dotnet-function-app RUN cd /src/dotnet-function-app && \ mkdir -p /home/site/wwwroot && \ dotnet publish *.csproj --output /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-isolated:3.0-dotnet-isolated5.0-appservice FROM mcr.microsoft.com/azure-functions/dotnet-isolated:3.0-dotnet-isolated5.0 ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ AzureFunctionsJobHost__Logging__Console__IsEnabled=true COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
Build & Push image
docker build -t willh/funapp2:latest . docker push willh/funapp2:latest
Deploy my function app with
--dry-run
func kubernetes deploy --name funapp2 --service-type NodePort --image-name willh/funapp2 --dry-run
There is only Secret been created.
data: AzureWebJobsStorage: VXNlRGV2ZWxvcG1lbnRTdG9yYWdlPXRydWU= FUNCTIONS_WORKER_RUNTIME: ZG90bmV0LWlzb2xhdGVk apiVersion: v1 kind: Secret metadata: name: funapp2 ---
Where is the other YAML of the deployment?
I was getting the same problem, issue was that my image was not properly built. The image in this case willh/funapp2 needs be a real function app.
I changed my DockerFile to be as simple as possible as follows but first did a publish in order to generate bin/Debug/net6.0/publish
FROM mcr.microsoft.com/azure-functions/dotnet:4
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . bin/Debug/net6.0/publish /home/site/wwwroot/
Then func kubernetes deploy ... worked
@SOFSPEEL The mcr.microsoft.com/azure-functions/dotnet:4
image you mentioned is for non-isolated function apps.
The issue described here only affects isolated functions since the functions.json
file is not generated for isolated funcs during the build process, and the current version of CLI tools uses information from this file to generate deploy yaml.
Though the band-aid mentioned above should also work when you're running isolated functions inside Docker images like mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated6.0
So still can't get the correct deployment.
I changed Docker to use "isolated"
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated6.0
ARG CONFIGURATION
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . bin/Debug/net6.0/publish /home/site/wwwroot/
I added band aid to csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Az.Functions.MetadataToJson" Version="1.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I'm running version
funapp2 % func -version
4.0.4653
when I run:
funapp2 % func kubernetes deploy --csharp --name junk --registry checkservicedev --write-configs
Running 'docker build -t checkservicedev/junk:latest ..
/RiderProjects/CharityDynamics.Gateway/funapp2'...done
Configuration written to functions.yaml%
The resultant output is:
data:
AzureWebJobsStorage: blah
FUNCTIONS_WORKER_RUNTIME: ZG90bmV0LWlzb2xhdGVk
apiVersion: v1
kind: Secret
metadata:
name: junk
---
and to be clear I'm expecting the Azure Core Tools to be generating stuff like: AzureWebJobsSecretStorageType = true
https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobskubernetessecretname
Indicates the Kubernetes Secrets resource used for storing keys. Supported only when running in Kubernetes. Requires that AzureWebJobsSecretStorageType be set to kubernetes. When AzureWebJobsKubernetesSecretName isn't set, the repository is considered read-only. In this case, the values must be generated before deployment. The [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local) generates the values automatically when deploying to Kubernetes.
Am I running func kubernetes deploy incorrectly?