FaaS: Working with kubeless in AKS — Part 2

Notes about my environment:

You need a k8s cluster. If you don’t have one, you can create one in AKS. The free tier (a.k.a. credits) is more than enough for tests. This link describes the steps to get an Azure Kubernetes Cluster: https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough

For my quick test I used AKS with the Cloud shell in the image above (which already includes the az and kubectl CLIs) for simplicity and speed. The az CLI shows the kube config with the command:

az aks get-credentials -resource-group jacace_aks -name jacace_aks_cluster

Don’t forget you can run kubeless in any k8s environment, incl. Openshift.

Steps to setup kubeless:

I followed the steps here: https://docs.bitnami.com/kubernetes/how-to/get-started-serverless-computing-kubeless/

There are 3 main steps when workign with kubeless:

#1 Creation of Custom Resource Definitions -CRDs-:

The following command will create the CRDs below: kubectl create -f kubeless-v1.0.6.yaml

  • ClusterRole: kubeless-controller-deployer
  • ClusterRoleBinding: kubeless-controller-deployer
  • CustomResourceDefinition:
  • functions.kubeless.io
  • httptriggers.kubeless.io
  • cronjobtriggers.kubeless.io

#2 Code and deploy your function:

The following command will deploy your function:

kubeless function deploy bikesearch -trigger-http -runtime python2.7 -handler city-bikes.find -from-file /tmp/city-bikes.py

About the command above: bikes.find is the name of the function in the code. In this example the code is the simple python function find below:

def find(request):
term = request.json[“term”]
url = “https://feeds.capitalbikeshare.com/stations/stations.json”
response = urllib2.urlopen(url)
stations = json.loads(response.read())

for station in stations[“stationBeanList”]:
if station[“stAddress1”].find(term) > -1:

return json.dumps(hits)

#3 Use your function

To call your function using kubeless with the following command: kubeless function call bikesearch -data ‘{“term”:”Dublin”}’

To call your function directly (from the cloud shell) use: curl -data ‘{“term”:”Dublin”}’ localhost:8080/api/v1/proxy/namespaces/default/services/bikesear ch/ -header “Content-Type:application/json”

There are other usefull kubeless commands as seen in the image below.

Opening the blackbox

I summarized some important facts below:

  • A Kubeless function is a K8s operator.
  • The CRDs create a controller to monitor the CRUD events of the functions and bind it with a handler. The controller uses the image: kubeless/function-controller:v1.0.6
  • When a new function is detected, kubeless does not build a new container, but instead deploys a new pod with an Init Container and a Func Container.
  • The init container copy/pastes the source code and dependencies to the designated directories and installs third-party dependencies. This is the image: kubeless/function-image-builder:v1.0.6
  • The Func Container loads the source code and dependencies prepared by the Int Container and executes the function. There are different func containers for different tech stacks, e.g.:
  • kubeless/nodejs@sha256:d36e13e876d0d92cbf4b9a62e181b27bfdaed5b9ec0b7c46759f9e11fce68c6e OR
  • kubeless/python@sha256:7630749ee027e873b24468fec066df6a7e7f3fd6a62695405189821b7114d1e1

For more information about this process please check: https://medium.com/@Alibaba_Cloud/kubeless-a-deep-dive-into-serverless-kubernetes-frameworks-1-fe3e581a27ec

Misc. Notes

  • Note: I’m not sure what’s the role of the image below: kubeless/unzip@sha256:4863100364496255de9bf8722a220dad7143ab277ac72435876eb8c93936e9d7
  • I did not see any statefulset, i.e. thw folloring command returned nothing: kubectl get statefulset -n kubeless
  • Obviouslly, I did see the CRDs, i.e.: the following command returned the below: kubectl get customresourcedefinition
  • cronjobtriggers.kubeless.io 2020–06–19
  • functions.kubeless.io 2020–06–19
  • httptriggers.kubeless.io 2020–06–19
  • There is a separate manifest for Openshift: kubeless-openshift-v1.0.6.yaml


Javier Caceres

Originally published at http://jacace.wordpress.com on July 17, 2020.

Hands-on Sr Software Manager / Architect based in Ireland. Views are my own. Linkedin: https://ie.linkedin.com/in/jacace Twitter: https://twitter.com/jacace