Add route to Kubeless function

Kubeless leverages Kubernetes ingress to provide routing for functions. By default, a deployed function will be matched to a Kubernetes service using ClusterIP as the service. That means that the function is not exposed publicly. Because of that, we provide the kubeless route command that can make a function publicly available. This guide provides a quick sample on how to do it.

Ingress controller

In order to create routes for functions in Kubeless, you must have an Ingress controller running. There are several options to deploy it. You can deploy it manually via the manifest we provide.

If you are on GKE, you can try this. Minikube also provide an addon for ingress, you can enable it executing minikube addons enable ingress. Please note that if you're intending to use our provided manifest on minikube, please disable the ingress addon.

Deploy function with Kubeless CLI

Try our example:

$ cd examples
$ kubeless function deploy get-python \
                    --trigger-http \
                    --runtime python2.7 \
                    --handler \
                    --from-file python/

$ kubectl get po
NAME                          READY     STATUS    RESTARTS   AGE
get-python-1796153810-krrf3   1/1       Running   0          2s

$ kubectl get svc
get-python    <none>        8080/TCP   44s

Create route

Kubeless support ingress command to create route to function.

$ kubeless route --help
ingress command allows user to list, create, delete routing rule for function on Kubeless

  kubeless route SUBCOMMAND [flags]
  kubeless route [command]

Available Commands:
  create      create a route to function
  delete      delete a route from Kubeless
  list        list all routes in Kubeless

Use "kubeless route [command] --help" for more information about a command.

We will create a route to get-python function:

$ kubeless route create route1 --function get-python

This command will create an ingress object. We can see it with kubectl (this guide is run on minikube):

$ kubectl get ing
NAME      HOSTS                              ADDRESS          PORTS     AGE
route1   80        59s

Kubeless creates a default hostname in form of Alternatively, you can provide a real hostname with --hostname flag like this:

$ kubeless route create route2 --function get-python --hostname
$ kubectl get ing
NAME      HOSTS                              ADDRESS          PORTS     AGE
route1   80        3m
route2                                         80        6s

But you have to make sure your hostname is configured properly.

You can test the new route with the following command:

$ curl --data '{"Another": "Echo"}' \
  --header "Host:" \
  --header "Content-Type:application/json" \
{"Another": "Echo"}

Enable TLS

By default, Kubeless doesn't take care of setting up TLS for its functions. You can do it manually by following the standard procedure of securing ingress. There is also a general guideline to enable TLS for your Kubernetes services using LetsEncrypt and Kube-lego written by Bitnami folks. When you have running Kube-lego, you can deploy function and create route with flag --enableTLSAcme enabled as below:

$ kubeless route create route1 --function get-python --enableTLSAcme

Running the above command, Kubeless will automatically create a ingress object with annotation 'true' set which will be used by Kube-lego to configure the service certificate.