Skip to main content
How to seamlessly deploy a python function on Fission over Kubernetes?
06 Apr 2017

How to seamlessly deploy a Python function on Fission over Kubernetes?

Introduction to Fission

Fission is a new open-source, Function as a Service framework built on Kubernetes. This serverless framework focuses on developer productivity and high performance and handles the details at the container or Kubernetes level. Fission enables developers to write short-lived functions in any language and map them to HTTP requests or event triggers. With this framework, you can create functions and instantly deploy them via CLI. Kubernetes offers a powerful and flexible orchestration system for Fission to upload and run code without worrying about building containers and managing Docker registries. The framework is extensible to any programming language; it currently supports NodeJS and Python.

Fission is open source under the Apache License. Fission can run on any platform where Kubernetes can run, i.e., in your private data center, public cloud, or laptop.

Fission architecture:

Fission architecture

Fission framework’s focus points:

  • Function- It represents a piece of code that follows the function interface.
  • Environment- It is a container with a web server and a dynamic loader that encompasses a function's language and runtime-specific parts.
  • Trigger- HTTP routes act as triggers that map an event to a function.

Installations:

To install Fission and set-up Kubernetes with Minikube:

For OSX:

colwin@colwins-mbp:~$ curl -LO https://storage.googleapis.com/kubernetes-release/release/
$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/
darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin

colwin@colwins-mbp:~$ curl -Lo minikube https://storage.googleapis.com/minikube/releases
/v0.14.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

colwin@colwins-mbp:~$ minikube start

For Linux:

colwin@colwins-mbp:~$ curl -LO https://storage.googleapis.com/kubernetes-release/release/
$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/
linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin

colwin@colwins-mbp:~$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/
v0.14.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

colwin@colwins-mbp:~$ minikube start

Alternatively if you prefer, you can use the Google Container Engine’s free trial to get a 3 node cluster.

Verify access to the cluster:

$ kubectl version

Running Fission on different environments:

The following commands are used to set up services with NodePort in case you are deploying it on Minikube or on  cloud service provider. These files run on 31313 and 31314 ports.

colwin@colwins-mbp:~$ kubectl create -f http://fission.io/fission.yaml
colwin@colwins-mbp:~$ kubectl create -f http://fission.io/fission-nodeport.yaml

Set the FISSION_URL and FISSION_ROUTER environment variable. The fission command line interface uses the FISSION_URL to find the server. The URL has to be prefixed with http://.

When using Minikube:

colwin@colwins-mbp:~$ export FISSION_URL=http://$(minikube ip):31313
colwin@colwins-mbp:~$ export FISSION_ROUTER=$(minikube ip):31314

Set the FISSION_URL and FISSION_ROUTER environment variables. The FISSION_URL and FISSION_ROUTER run on 31313 and 31314 ports respectively.

When using GKE or other cloud service provider:

The following instructions apply to GKE or other cloud service provider with load balancer service type:

$ kubectl create -f  http://fission.io/fission.yaml
$ kubectl create -f http://fission.io/fission-cloud.yaml

The FISSION_URL and FISSION_ROUTER stores the external IP address of the controller and router services.

$ export FISSION_URL=http://$(kubectl --namespace fission get svc

controller -o=jsonpath='{..ip}')
$ export FISSION_ROUTER=$(kubectl --namespace fission get svc router
-o=jsonpath='{..ip}')

To check the status of the IP address use the following command:

kubectl --namespace fission get svc.

Steps to set up the services needed on Minikube:

colwin@colwins-mbp:~$ kubectl create -f http://fission.io/fission.yaml
namespace "fission" created
namespace "fission-function" created
deployment "controller" created
deployment "router" created
service "poolmgr" created
deployment "poolmgr" created
deployment "kubewatcher" created
service "etcd" created
deployment "etcd" created

colwin@colwins-mbp:~$ kubectl create -f http://fission.io/fission-nodeport.yaml
service "router" created
service "controller" created

Installing the Command line interface:

CLI for MAC:

colwin@colwins-mbp:~$ curl http://fission.io/mac/fission > fission &&

chmod +x fission && sudo mv fission/usr/local/bin/

CLI for Linux:

colwin@colwins-mbp:~$ curl http://fission.io/linux/fission > fission &&

chmod +x fission && sudo mv fission/usr/local/bin/

Here's how you’d write a "hello world"  with Fission:

Create new python file:

colwin@colwins-mbp:~$ cat hello_world.py

def main():

    return “Hello, World!\n”

Check if the environment is already created for  python application:

colwin@colwins-mbp~$ fission env get --name python

Failed to get environment: (Error 0) HTTP error 500

Create new environment for python application:

colwin@colwins-mbp:~$ fission env create --name python --image fission/python-env

environment 'python' created

Check if image env is created:

colwin@colwins-mbp:~$ fission env get --name python

NAME UID IMAGE

python 34a264a1-4fb2-4b17-b13c-4bc6d199049a fission/python-env

Create new function that uses the image:

colwin@colwins-mbp:~$ fission function create --name hello_world

 --env python --code hello_world.py --url /hello_world --method GET

function 'hello_world' created

route created: GET /hello_world -> hello_world

Test if the function runs:

colwin@colwins-mbp:~$ curl http://$FISSION_ROUTER/hello_world

Hello, World!

Conclusion:

Fission enables you to spin up machines, auto-scale databases and infrastructure. It allows developers to easily build additional tools and integrate as and when required. The goal with Fission is to make consumption of Kubernetes micro-services even easier.

Subscribe to our feed

select webform