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:

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:

  1. Create the sample go serverless application
  1. cat <<EOF | kubectl apply -f -
  2. apiVersion: core.openfunction.io/v1beta2
  3. kind: Function
  4. metadata:
  5. name: sample-go-app
  6. namespace: default
  7. spec:
  8. build:
  9. builder: openfunction/buildah:v1.23.1
  10. shipwright:
  11. strategy:
  12. kind: ClusterBuildStrategy
  13. name: buildah
  14. srcRepo:
  15. revision: main
  16. sourceSubPath: apps/buildah/go
  17. url: https://github.com/OpenFunction/samples.git
  18. image: openfunctiondev/sample-go-app:v1
  19. imageCredentials:
  20. name: push-secret
  21. serving:
  22. template:
  23. containers:
  24. - imagePullPolicy: IfNotPresent
  25. name: function
  26. triggers:
  27. http:
  28. port: 8080
  29. version: v1.0.0
  30. workloadRuntime: OCIContainer
  31. EOF
  1. Check the application status

You can then check the serverless app’s status by kubectl get functions.core.openfunction.io -w:

  1. kubectl get functions.core.openfunction.io -w
  2. NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
  3. sample-go-app Succeeded Running builder-jgnzp serving-q6wdp http://sample-go-app.default.svc.cluster.local/ 22m
  1. 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:

  1. kubectl run curl --image=radial/busyboxplus:curl -i --tty
  2. 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:

  1. Create the sample Java serverless application
  1. cat <<EOF | kubectl apply -f -
  2. apiVersion: core.openfunction.io/v1beta2
  3. kind: Function
  4. metadata:
  5. name: sample-java-app-buildpacks
  6. namespace: default
  7. spec:
  8. build:
  9. builder: cnbs/sample-builder:alpine
  10. srcRepo:
  11. revision: main
  12. sourceSubPath: apps/java-maven
  13. url: https://github.com/buildpacks/samples.git
  14. image: openfunction/sample-java-app-buildpacks:v1
  15. imageCredentials:
  16. name: push-secret
  17. serving:
  18. template:
  19. containers:
  20. - imagePullPolicy: IfNotPresent
  21. name: function
  22. resources: {}
  23. triggers:
  24. http:
  25. port: 8080
  26. version: v1.0.0
  27. workloadRuntime: OCIContainer
  28. EOF
  1. Check the application status

You can then check the serverless app’s status by kubectl get functions.core.openfunction.io -w:

  1. kubectl get functions.core.openfunction.io -w
  2. NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
  3. sample-java-app-buildpacks Succeeded Running builder-jgnzp serving-q6wdp http://sample-java-app-buildpacks.default.svc.cluster.local/ 22m
  1. 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:

  1. kubectl run curl --image=radial/busyboxplus:curl -i --tty
  2. curl http://sample-java-app-buildpacks.default.svc.cluster.local