In this tutorial, we will learn how to deploy Flask Microservice as a Serverless Function in OpenFaas. In one of my previous tutorials, we have already seen how to create a Flask microservice. We will use that microservice as a reference and deploy it on OpenFaas as a Function.

What is Serverless?

Serverless is an architectural pattern where the business logic are written as functions that can be executed in a stateless manner. Serverless does not mean executing code without servers. It merely means we don’t have to provision for hardware and infrastructure while writing our code. The application still runs on servers, which are managed by third-party services.

FaaS OpenFaas

Function-as-a-Service (FaaS) is a serverless model that provides the ability to develop, run, and manage application functionalities without the complex infrastructure mostly associated with building and deploying microservices applications. Building an application by following this model is one way of achieving a serverless architecture, and is typically used when building microservices applications.

Docker and Kubernetes

Docker is a platform that uses OS-level virtualization to deliver software in packages called as containers. Each of these containers bundles its own software, libraries and configuration files. Although, they are isolated from one another, they can communicate with each other through well-defined channels. Containers are a good way of developing and deploying microservices.

Kubernetes is a portable, extensible, and open-source platform that facilitates the automation of the deployment, scaling, and operations of application containers (Docker containers, in this case) across clusters of hosts.

For further details on Kubernetes please check: https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

OpenFaas

OpenFaaS is an open-source framework that enables implemention of the serverless architecture on Kubernetes, using Docker containers for storing and running functions. OpenFaaS makes it easy for developers to deploy event-driven functions and microservices to Kubernetes without repetitive, boiler-plate coding. It allows you to package your code or an existing binary in a Docker image to get a highly scalable endpoint with auto-scaling and metrics.

For further details on OpenFaas please check: https://docs.openfaas.com/

We will use the following steps to deploy Flask microservice as a Serverless Function in OpenFaas:

  1. Setting up Kubernetes and OpenFaas
  2. Dockerizing Flask Application
  3. Creating a Custom Function
  4. Deploying the Function
  5. Testing the Function

#serverless #flask #kubernetes #python

Serverless with OpenFaas, Kubernetes, and Python
2.45 GEEK