As serverless is becoming more and more an interesting architecture to look at, I did some small experiments at home and these are the end results.
I am assuming you have at least an Ubuntu 18.04 installed.
you can install microk8s through snap
sudo snap install microk8s –classicAnd i strongly suggest adding the following alias
sudo snap alias microk8s.kubectl kubectlThis command should return yes
kubectl auth can-i create podsWe create then the namespace
kubectl create ns kubelessand install kubeless, the kubernetes solution for FaaS based on kubernetes. next coming commands are straight from their documentation pages available here setting the release
export RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/latest | grep tag_name | cut -d ‘“’ -f 4)creating the initial configuration
kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-$RELEASE.yamladditional bash magic to determine your os
export OS=$(uname -s| tr ‘[:upper:]’ ‘[:lower:]‘)downloading and installing kubeless in your system under /usr/local/bin
curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_$OS-amd64.zip unzip kubeless_$OS-amd64.zip sudo mv bundles/kubeless_$OS-amd64/kubeless /usr/local/bin/
Before launching your first sample you need to create a config for kubeless. –flatten=true will create a configuration that include certification authority so you can safely connect without having to add insecure-tls option
kubectl config view –flatten=true >>~/.kube/config
Now let’s create a sample python file and let’s call it test2.py
def echoing_commands(event, context):
print (event)
return event[‘data’]
you can now deploy your amazing function
kubeless function deploy hello2 –runtime python3.6 –from-file test2.py –handler test2.echoing_commands
Wait for it to be ready:
kubeless function ls hello2 NAME NAMESPACE HANDLER RUNTIME DEPENDENCIES STATUS
hello2 default test2.echoing_commands python3.6 1⁄1 READY
and then you can test it with
kubeless function call hello2 –data “I am working” I am working
and that’s it, you have a serverless infrastructure at home! Now you just need some reasons to use it.