blademainer / refunc

A Kubernetes native serverless platform.

Home Page:https://refunc.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refunc

Refunc is a Kubernetes native serverless platform.

Refunc Architecture

Features

  • Easy of use - Embrace the serverless ecosystem with an AWS Lambda compatible API and runtimes
  • Portable - Run everywhere that has Kubernetes
  • Scale from zero - Autoscale from zero-to-many and vice versa
  • Extensible - Runtime compatibility layer (lambda and other clouds' function), transport layer (NATS based for now)

Quick Start

Before starting, you need a Kubernetes cluster. You can use minikube to run a minimal Kubernetes cluster locally.

If you'd like to run on macOS, Docker for Mac with Kubernetes enabled is recommended.

Install Refunc

Install refunc-play, a minimal setup of Refunc, using the following commands:

# This will create namespace `refunc-play` and deploy components in it
docker run --rm -it refunc/refunc refunc play gen -n refunc-play | kubectl apply -f -
# create runtime python3.7
kubectl create -n refunc-play -f \
https://github.com/refunc/lambda-python3.7-example/releases/download/v0.0.2/xenv.yaml

Here we use the python3.7 runtime as an example. Currently Refunc supports all AWS provided runtimes as well as some converted runtimes, check refunc/lambda-runtimes to learn more.

The AWS Way

Refunc uses an AWS API compatible gateway to provide Lambda and S3 services, which makes it possible to use the AWS CLI to manage functions locally.

Before starting, we need to forward the gateway to your localhost:

kubectl port-forward deployment/aws-api-gw 9000:80 -n refunc-play

Download the pre-built function for convenience:

cd /tmp
wget https://github.com/refunc/lambda-python3.7-example/releases/download/v0.0.1/lambda.zip

Create Function

aws --endpoint-url=http://127.0.0.1:9000 \
lambda create-function --function-name localtest \
--handler lambda_function.lambda_handler \
--zip-file fileb:///tmp/lambda.zip \
--runtime python3.7 \
--role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role

Invoke Function

aws --endpoint-url=http://127.0.0.1:9000 \
lambda invoke --function-name localtest /tmp/output.json && cat /tmp/output.json

The Refunc Way

Let's create a Lambda function using the python3.7 runtime with an HTTP endpoint:

kubectl create -n refunc-play -f https://github.com/refunc/lambda-python3.7-example/releases/download/v0.0.2/inone.yaml

Forward the Refunc HTTP gateway to your localhost:

kubectl port-forward deployment/refunc-play 7788:7788 -n refunc-play

Now, it's OK to send a request to your function:

curl -v  http://127.0.0.1:7788/refunc-play/python37-function

User Interface

Internally we use Rancher to build our PaaS and other internal services. Currently there is a simple management UI forked from rancher/ui which is backed by our Rancher API compatible server.

functions.png

License

Copyright (c) 2018 refunc.io

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

A Kubernetes native serverless platform.

https://refunc.io

License:Apache License 2.0


Languages

Language:Go 98.4%Language:Shell 1.0%Language:Makefile 0.6%Language:Dockerfile 0.1%