Serverless Applications
In addition to building and running Serverless Functions, you can also build and run Serverless Applications with OpenFuntion.
OpenFunction support building source code into container images in two different ways:
- Using Cloud Native Buildpacks to build source code without a
Dockerfile
- Using Buildah or BuildKit to build source code with a
Dockerfile
To push images to a container registry, you’ll need to create a secret containing the registry’s credential and add the secret to
imageCredentials
. Please refer to the prerequisites section for more info.
Build and run a Serverless Application with a Dockerfile
If you already created a Dockerfile
for your application like this Go Application, you can build and run this application in the serverless way like this:
- Create the sample go serverless application
cat <<EOF | kubectl apply -f -
apiVersion: core.openfunction.io/v1beta2
kind: Function
metadata:
name: sample-go-app
namespace: default
spec:
build:
builder: openfunction/buildah:v1.23.1
shipwright:
strategy:
kind: ClusterBuildStrategy
name: buildah
srcRepo:
revision: main
sourceSubPath: apps/buildah/go
url: https://github.com/OpenFunction/samples.git
image: openfunctiondev/sample-go-app:v1
imageCredentials:
name: push-secret
serving:
template:
containers:
- imagePullPolicy: IfNotPresent
name: function
triggers:
http:
port: 8080
version: v1.0.0
workloadRuntime: OCIContainer
EOF
- Check the application status
You can then check the serverless app’s status by kubectl get functions.core.openfunction.io -w
:
kubectl get functions.core.openfunction.io -w
NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
sample-go-app Succeeded Running builder-jgnzp serving-q6wdp http://sample-go-app.default.svc.cluster.local/ 22m
- Access this application
Once the BUILDSTATE
becomes Succeeded
and the SERVINGSTATE
becomes Running
, you can access this Go serverless app through the address in the ADDRESS
field:
kubectl run curl --image=radial/busyboxplus:curl -i --tty
curl http://sample-go-app.default.svc.cluster.local
Here you can find a Java Serverless Applications (with a Dockerfile) example.
Build and run a Serverless Application without a Dockerfile
If you hava an application without a Dockerfile
like this Java Application, you can also build and run your application in the serverless way like this Java application:
- Create the sample Java serverless application
cat <<EOF | kubectl apply -f -
apiVersion: core.openfunction.io/v1beta2
kind: Function
metadata:
name: sample-java-app-buildpacks
namespace: default
spec:
build:
builder: cnbs/sample-builder:alpine
srcRepo:
revision: main
sourceSubPath: apps/java-maven
url: https://github.com/buildpacks/samples.git
image: openfunction/sample-java-app-buildpacks:v1
imageCredentials:
name: push-secret
serving:
template:
containers:
- imagePullPolicy: IfNotPresent
name: function
resources: {}
triggers:
http:
port: 8080
version: v1.0.0
workloadRuntime: OCIContainer
EOF
- Check the application status
You can then check the serverless app’s status by kubectl get functions.core.openfunction.io -w
:
kubectl get functions.core.openfunction.io -w
NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
sample-java-app-buildpacks Succeeded Running builder-jgnzp serving-q6wdp http://sample-java-app-buildpacks.default.svc.cluster.local/ 22m
- Access this application
Once the BUILDSTATE
becomes Succeeded
and the SERVINGSTATE
becomes Running
, you can access this Java serverless app through the address in the ADDRESS
field:
kubectl run curl --image=radial/busyboxplus:curl -i --tty
curl http://sample-java-app-buildpacks.default.svc.cluster.local