Azure / Azure-Functions

1.11k stars 196 forks source link

Azure functions serverless app model with Kubernetes #1225

Open VenkateshSrini opened 5 years ago

VenkateshSrini commented 5 years ago

Hi, I have been contemplating with various container based serverless framework. Need less to say I'm fan of Azure serverless owing to its various features like easy way of writing custom binding, New natural dependency injection and so on. But what I see is Azure function on container offers Function as service model in container but not a serverless.

What I mean even when I containerize and deploy it kubernetes when no request is coming the scale to zero ( as it happens in Azure serverless) is not happening. In a managed offering, I still see that I'm charged for running the container

I also tried to use Azure function with KNative. There what is happening is since the Azure function runtime is coupled with the serverless code in container, when I scale it down to zero, the runtime also dies and it is always a cold start.

Is it possible for Microsoft community to design or recommend an approach for Azure function on container such that when using platform container, we device such a way of execution such that the serverless runtime is always in hot start and is shared. We dynamically place functions alone in them on need basis and when done, clean up function but the severless runtime is present as is. Also even when using container managed offering like (AKS) we will only charged for function and not the serverless runtime running cost.

ahmelsayed commented 5 years ago

:) Good timing.

Can you check this out https://github.com/kedacore/keda/wiki/Using-Azure-Functions-with-Keda-and-Osiris

If you use func >= 2.7.* you should be able to do

func kubernetes install --namespace scale-controller # or whatever namespace

This will install 2 components into your kubernetes cluster. Keda and Osiris

Keda handles scale to-and-from-zero for non-http event sources. It also integrates with native Kubernetes HPA to scale your functions 1-N based not only based on CPU and memory, but also based on the specific event source metric. Keda exposes a custom metrics API server that HPA queries to make scale decisions based on queueLength, topic partitions, etc.

Osiris is an existing k8s project that handles scale to-and-from-zero for http triggers. The core-tools (>= 2.7) knows how to integrate with it. I think there is still more work for http trigger scenarios to be done though.

Running

func kubernetes deploy --name {name} \
                       --namespace {namespace} \
                       --image-name {image-name} # or `--registry {registry-or-dockerhub-alias}` to build and push current dir to your registry.

This will inspect your functions in the image {image-name} and create 2 kubernetes deployments. One for non-http that's managed by Keda, and one that has all the http functions that's managed by Osiris.

This is an initial release that we just announced, so any feedback is very appreciated

VenkateshSrini commented 5 years ago

This is close but not exactly what I was envisioning. I was expecting something where the function runtime always remain hot and function alone comes up and dies. Even now when we build the container (Azure function) the azure function runtime is built in in the same container as that of the code. So ideal when I start or restart a container, there is going to additional overload of starting function runtime and then executing my function

ahmelsayed commented 5 years ago

I understand what you're asking for, though I don't think we have current plans for that. I'll move the issue to the general repo since it's not a core-tools ask.

also tagging few people. /cc @jeffhollan @anirudhgarg