Running serverless functions on premises using OpenFaas with Kubernetes

Earlier most of companies had monolithic architecture for their cloud applications (all the things in a single package). Nowadays companies are decomposing their monolithic app’s business functions in to several micro-services (Isolated component that has single responsibility). Thus thereafter serverless concept came with kind of different concept.

Serverless!! really running without a server ?

Nothing can be executed without servers. We need resources to do calculations 😎. Whereas the word “serverless” highlights these key principles

  1. Simplicity
  2. Less maintenance
  3. Inexpensive

Serverless function has an endpoint that triggers a function written in a programming language.We don’t need to worry about the server and execution environment. Cloud provider’s modules will take care of those.

Serverless on premises?

Running a serverless function is very easy. We can simply use AWS Lambda or GCP function or whatever from cloud providers. So how about if we do have some servers of our own. If you are running Kubernetes orchestration engine on servers, it’s very easy using OpenFaas.

OpenFass — OpenFaaS — Serverless Functions Made Simple for Docker & Kubernetes

Open Faas (Function as a service) is a framework for creating serverless functions on Kubernetes or Docker. It’s an open source project released under MIT License and written in Go.

Setting up OpenFaas on Kubernetes

According to my researches Rancher is the best tool to build a kubernetes cluster on premises(on bare metal servers or on virtual machines). Whole process can be done simply by hitting few kubectl commands with your keyboard 🧐.

Clone openfaas for Kubernetes repo

Download and deploy namespace yaml

Deploy openfaas services

Open rancher dashboard and see newly created workloads

Image for post
Image for post

Gateway and prometheus have web interfaces 😀.

OpenFass Architecture

Image for post
Image for post

OpenFaas watchdog module converts http messages to stdin then it will be passed to our functions and stdout vice versa. Prometheus is used for analytics. API Gateway handles the routing using client request-to-function mapping strategies. OpenFass runs each function in separate pods. Therefore if we scale up our pods, the replicas of specific function will be increased 😋.

Deploying a function

You can deploy any working binary as a function (Since it will deal with stdin and stdout). As an example let’s see about c#

Download C# Function template, it is having a simple application that gives the stdin content as the output

Create docker image and push to hub

Deploy the function via openfaas dashboard

Image for post
Image for post

Once the function is deployed. You will be able to find the url

Image for post
Image for post

Open Postman ,simply POST few characters

Image for post
Image for post

Motivation for open source projects

Watch the story of Alex Ellis(founder of openfaas) and see how community gather around open source projects.

Happy Faas !! 😄

Written by

Software Engineer at 99x | Apache PMC member | Open Source Contributor (Author of Neutralinojs) | Technical Writer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store