Running Knative Functions with the Azure Functions Runtime
Azure has established itself has real competition to AWS in the last few years. Their new commitment to Open-source software has been impressive and their Kubernetes team is a major contributor in the community.
When talking Serverless, AWS Lambda is definitely leading the pack, but Azure functions are very often talked about. I had a look at Azure functions recently and I have to say that I was quite impressed: Azure functions are cool
Interestingly, while we have had to rely on a third-party reverse-engineering of Lambda to get a look at the function runtime. Azure itself released its runtime in the shape of Azure function core tool: func.
With func you can create a function, load the extensions that are needed to configure the event binding that you need and then create a container image from it.
There have been several blogs over the last few months about running Azure functions in Kubernetes.
However, with the advent of Knative (which gives us auto-scaling, internal build system and additional eventing), it begs to wonder: “Can I run my functions in the Azure function runtime within knative?”
The answer is a resounding Yes and here is how:
Build Your Function with func
This is a summary, for the full step by step please check out the main repository and definitely we would love the help to make it better.
> As a sign of how times have changed I will know talk about a MSFT tool and even tell you to install .NET. That said, I learned basic at 10 years old and my first computers were all running MS-DOS. Close the Aparte.
Microsoft has developed a tool to help Azure users write Azure functions, at the CLI it is called func and you get it by installing the Azure function core tools which has .NET dependency.
The .NET bit might be a bit challenging on some OS, so we prepared a Docker image for you gcr.io/triggermesh/azure-func
To start developing your function create an empty directory and start our image in interactive mode:
You can then initialize your function, create an HTTP trigger and start it:
There might be a few gotchas but that’s really all there is to it.
Deploy in Knative or TriggerMesh Cloud
Since you created this function within a Docker container, you can easily package it as a Docker image and hence run it in knative.
For the impatient, the TLDR CLI commands to do it will look like this:
For the longer version, check the full repository. Here is a summary:
We have prepared a Knative build-template for it. The core of it is a kaniko based container build using the Docker image that we created with func. First, we write a Dockerfile in the workspace and then we do the build and publish the image to a registry.
Create this template in your TriggerMesh account (or your own knative environment):
With a Build template called azure-runtime deployed you can create your function using a Configuration object, here is an example from a personal test.
And Voila ! Just like that, you have created a Node.js function using the Azure function runtime and you are now running it in Knative.