Kubeless brings functions as a service to Kubernetes & on-prem

Aug 30, 2017

One of the primary goals of the serverless framework is to provide a platform-agnostic cloud experience for developers.

We want it to be easy for people to write code once and have the freedom to choose where that code runs.

That is why we are super excited to announce a brand new serverless provider Kubeless to expand where your functions can run.

Introducing Kubeless

Made by the the fine folks over at Bitnami, Kubeless is a Kubernetes-native way to deploy and manage your serverless functions via the serverless framework.

Kubeless lets you deploy small bits of code without having to worry about the underlying infrastructure. It leverages Kubernetes resources to provide auto-scaling, API routing, monitoring, troubleshooting and more.

Checkout the Kubeless Docs

This integrations brings functions and events into your Kubernetes cluster.

functions and events are logically grouped together in services.

Let's explore those two main concepts and how they pertain to Kubeless.

🔄 Functions

A Function is an independent unit of deployment, like a microservice. It's merely code, deployed in the cloud, that is most often written to perform a single job such as:

  • Saving a user to the database
  • Processing a file in a database
  • Performing a scheduled task (To be added in newer versions)

The framework is designed to help you easily develop and deploy Functions into your Kubernetes cluster.

⚡ Events

Anything that triggers a Kubeless Function to execute is regarded by the Framework as an Event.

Here are some examples of events:

  • An API Gateway HTTP endpoint (e.g., for a REST API)
  • A Kafka queue message (e.g., a message)
  • A scheduled timer (e.g., run every 5 minutes) (To be added in newer versions)

See list of supported events

📡 Services

Functions and events are grouped together in services and configured with a serverless.yml file.

serverless.yml is where you define your Functions and the Events that trigger them. Continue reading for an example at the end of this post.

Note: serverless services are not to be confused with Kubernetes services


Serverless + Kubeless for on-prem functions

Not a day goes by without a user of the framework shooting us an email asking about on-prem support.

It's a widely requested feature and Kubeless delivers on-premise to the enterprise.

We are very excited to see what people start building with it.


Getting Started with Serverless & Kubeless

Make sure you have the serverless framework installed on your machine.

# Install serverless framework if you haven't already
npm i serverless -g

Then create a new service with the sls create command.

# Create a new Serverless Service/Project
$ serverless create --template kubeless-python --path new-project
# Change into the newly created directory
$ cd new-project
# Install npm dependencies
$ npm install

Kubeless runs on Kubernetes, therefor you need a working Kubernetes cluster in order to run it.

See the guide on installing Kubeless in your Kubernetes cluster to finish setup.

Project Structure

Below is a quick overview of the kubeless-python template for an example hello world python service running on Kubeless. For an in-depth overview of kubeless, see the provider docs.

|- handler.py # function code
|- package.json # function deps
|- serverless.yml # service configuration

The serverless.yml defines what functions will be deployed and what events they respond to.

# The service name
service: hello-world

# Where the service lives
provider:
  name: kubeless
  runtime: python2.7

# Adding kubeless provider functionality
plugins:
  - serverless-kubeless

# Functions to be packaged and deployed
functions:
  hello:
    handler: handler.hello

The simple python code returns a simple JSON response.

import json

def hello(request):
    body = {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "input": request.json
    }

    response = {
        "statusCode": 200,
        "body": json.dumps(body)
    }

    return response

Deployment

After hooking up kubeless to your Kubernetes cluster you can deploy your functions with:

serverless deploy -v

The Serverless Framework translates all syntax in serverless.yml to the Function object API calls to provision your Functions and Events.

For each function in your serverless.yml file, Kubeless will create an Kubernetes Function object and for each HTTP event, it will create a Kubernetes service.

Here’s what you need to get started with the Kubeless plug-in now:

Start here in our docs.

If you have questions or comments about the integration, we'd love to hear from you in the comments below or over on the serverless forums.

Subscribe to our newsletter to get the latest product updates, tips, and best practices!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.