Run Azure Function Service Bus Trigger in Docker Container locally and K8S

Viewed 788

This may be a simple thing but I'm struggling to get my head around how to run a Service Bus trigger (or any background task trigger) under Azure Functions 3.0, in a docker container, in order to run locally (for testing) and eventually in K8S.

Most of the examples I've found (including from MS) appear to use the simple HTTP Trigger. Although I'm using a compiled C# function, I found one python example that was for Service Bus, but it's very unclear how you actually run the function once in the container locally for testing or in a none AKS environment. The examples I've found don't reference this step - it appears to be 'magic'.

I've used func init --docker-only --csharp to patch together this docker file:

FROM mcr.microsoft.com/azure-functions/dotnet:3.0

COPY bin/Release/netcoreapp3.1/publish/bin/ /home/site/wwwroot
ENV AzureWebJobsScriptRoot=/home/site/wwwroot

but what this doesn't tell me is how I need to start the azure function. The azure functions base docker image doesn't contain the func tools so that I can call func xxxxxx in my dockerfile to start the function.

I'm expecting something like an ENTRYPOINT that I'd use for a normal web api or some other step to invoke a BASH command to start the azure function but the default dockerfile created by 'func' doesn't include this.

I don't think it matters but eventually we are going to run these on a local K8S deployment for development testing - they may never actually run in AKS itself.

3 Answers

I am trying to get it to work as well but the one thing that give the most problems for me is the connection strings. These are given via the environment variables.

For service bus look really into when to use the string of the namespace and when to use the one of the queue/topic.

If you want to look more into some documentation of azure function in k8s look into the package KEDA.

Another issue that I have found recently was that because I had the following NuGet Package installed in the Azure Functions project, the functions would never get triggered and also no output of any errors would show up in the Logs. After I removed the package and the call in Startup, everything started working properly.

Do not add this package:

Microsoft.ApplicationInsights.Kubernetes
Related