2.4 KiB
Read this on the main serverless docs site
Kubeless HTTP Events
The first type of events that you can create in Kubeless are HTTP events.
When creating HTTP events, Kubeless will create a Kubernetes Service that you can call through Serverless or directly calling the HTTP endpoint.
Single HTTP Endpoint
If you don't specify the type of event in your serverless.yml Kubeless will create an HTTP endpoint by default:
service: testing-pkg
provider:
name: kubeless
runtime: python2.7
plugins:
- serverless-kubeless
functions:
hello:
handler: handler.hello
When deploying this serverless.yml file, Kubeless will create a Kubernetes service with a single endpoint. Calling that HTTP endpoint will trigger the function associated with it.
Multiple endpoints with Ingress rules
You can also deploy several endpoints in a single serverless.yml file:
service: todos
provider:
name: kubeless
runtime: nodejs6
plugins:
- serverless-kubeless
functions:
create:
handler: todos-create.create
events:
- http:
path: /create
read-all:
handler: todos-read-all.readAll
events:
- http:
path: /read-all
read-one:
handler: todos-read-one.readOne
events:
- http:
path: /read
update:
handler: todos-update.update
events:
- http:
path: /update
delete:
handler: todos-delete.delete
events:
- http:
path: /delete
If the events HTTP definitions contain a path attribute, when deploying this Serverless YAML definition, Kubeless will create the needed Ingress rules to redirect each of the requests to the right service:
kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
ingress-create * 192.168.99.100 80 2m
ingress-delete * 192.168.99.100 80 2m
ingress-read-all * 192.168.99.100 80 2m
ingress-read-one * 192.168.99.100 80 2m
ingress-update * 192.168.99.100 80 2m