No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Portable Azure Functions

The Azure Functions runtime can be run in many environments. As an open-source project, you can use the exact same Azure Functions runtime locally, on Kubernetes, and on Azure.

This simple example project outlines an easy set of steps to run an Azure Function in multiple environments. Below are steps to run the Azure Function:

  • Locally as an Azure Function
  • Locally as a Docker image
  • On Kubernetes
  • On Azure Functions (fully serverless)

This project includes a basic HTTP-triggered Hello World function (under http/index.js). If you are new to the Azure Functions programming model, this developers guide is helpful for learning important concepts.

The function itself is a very standard Azure Function. The only difference is the simple Dockerfile at the root of the function app.

➡️ Before getting started, remove -REMOVE from local.settings.json-REMOVE ⬅️
The file should be named local.settings.json. This will now not be committed to source control. local.settings.json should never be committed to source control as it often contains connection strings and secrets.

Running your function locally

You can run your Azure function locally using the func command line tool. Alternatively, you can create a docker image and run that image locally.

Running as an Azure Function locally


To run and breakpoint debug this function with Visual Studio Code:

To run this function otherwise:

Run as a docker image locally


To run this function in this environment:

  • From project root, run docker build -t IMAGENAME .
    • For example, for IMAGENAME, I use mhoeger/func-test-docker
  • Run docker run -p 8080:80 -d IMAGENAME
  • Navigate to http://localhost:8080/api/sayHello/My-Input
  • Stop with docker stop [IMAGE ID]

Run image on Kubernetes


  • Follow the prerequisites and steps for running an image locally
  • kubectl - install from here
  • It is assumed that you have already deployed a Kubernetes instance and connected with kubectl

To run this function in this environment:

  • Publish your image to a registry service such as Docker Hub using docker push IMAGENAME
  • Create a Kubernetes deployment with the published image
    • For example: kubectl run DEPLOYMENTNAME --replicas=5 --image=IMAGENAME --port=80
  • Expose Kubernetes deployment
    • For example: kubectl expose deployment DEPLOYMENTNAME --type=LoadBalancer --name=SERVICENAME

Other helpful commands

To update an image on a deployment:

  • kubectl set image deployments SERVICENAME SERVICENAME=NEW_IMAGENAME

To delete a deployment:

  • Run kubectl delete services SERVICENAME
  • Run kubectl delete deployment DEPLOYMENTNAME

Run serverless on Azure

You can deploy your Azure Function in one of the following ways:

Do more!

  • Try different trigger types and explore input/output bindings using extensions to integrate with other Azure services
  • Use Durable Functions to define complex orchestration patterns with Functions using code (ex: fan-out/fan-in and async HTTP APIs)