Skip to content

Commit 9130bc1

Browse files
authored
Add serverless app guide (#314)
Signed-off-by: Benjamin Huo <benjamin@kubesphere.io> Signed-off-by: Benjamin Huo <benjamin@kubesphere.io>
1 parent dd0384f commit 9130bc1

File tree

4 files changed

+147
-4
lines changed

4 files changed

+147
-4
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: "Serverless Applications"
3+
linkTitle: "Serverless Applications"
4+
weight: 3310
5+
description:
6+
---
7+
In addition to building and running Serverless Functions, you can also build and run Serverless Applications with OpenFuntion.
8+
9+
OpenFunction uses [Shipwright](https://github.com/shipwright-io/build) to build source code into container images, [Shipwright](https://github.com/shipwright-io/build) supports to build source code in two different ways:
10+
- Using [Cloud Native Buildpacks](https://buildpacks.io/) to build source code without a `Dockerfile`
11+
- Using [Buildah](https://buildah.io/) or [BuildKit](https://github.com/moby/buildkit) to build source code with a `Dockerfile`
12+
13+
> 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`.
14+
> Please refer to the [prerequisites](../../getting-started/Quickstarts/prerequisites) section for more info.
15+
16+
## Build and run a Serverless Application with a Dockerfile
17+
18+
If you already created a `Dockerfile` for your application like this [Go Application](https://github.com/OpenFunction/samples/tree/main/apps/buildah/go), you can build and run this application in the serverless way like [this](https://github.com/OpenFunction/samples/blob/main/apps/buildah/go/sample-go-app.yaml):
19+
20+
1. Create the sample go serverless app
21+
22+
```shell
23+
cat <<EOF | kubectl apply -f -
24+
apiVersion: core.openfunction.io/v1beta1
25+
kind: Function
26+
metadata:
27+
name: sample-go-app
28+
spec:
29+
version: "v1.0.0"
30+
image: "openfunctiondev/sample-go-app:v1"
31+
imageCredentials:
32+
name: push-secret
33+
#port: 8080 # default to 8080
34+
build:
35+
builder: openfunction/buildah:v1.23.1
36+
srcRepo:
37+
url: "https://github.com/OpenFunction/samples.git"
38+
sourceSubPath: "apps/buildah/go"
39+
revision: "main"
40+
shipwright:
41+
strategy:
42+
name: buildah
43+
kind: ClusterBuildStrategy
44+
serving:
45+
runtime: knative
46+
template:
47+
containers:
48+
- name: function
49+
imagePullPolicy: IfNotPresent
50+
EOF
51+
```
52+
53+
2. Check the serverless app status
54+
55+
You can then check the serverless app's status by `kubectl get functions.core.openfunction.io -w`:
56+
57+
```shell
58+
kubectl get functions.core.openfunction.io -w
59+
NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
60+
sample-go-app Succeeded Running builder-jgnzp serving-q6wdp http://sample-go-app.default.svc.cluster.local/ 22m
61+
```
62+
63+
3. Access the function
64+
65+
Once the `BUILDSTATE` becomes `Succeeded` and the `SERVINGSTATE` becomes `Running`, you can access this Go serverless app through the address in the `ADDRESS` field:
66+
67+
```shell
68+
kubectl run curl --image=radial/busyboxplus:curl -i --tty
69+
curl http://sample-go-app.default.svc.cluster.local
70+
```
71+
72+
> [Here](https://github.com/OpenFunction/samples/tree/main/apps/buildah/java) you can find a Java Serverless Applications (with a Dockerfile) example.
73+
74+
## Build and run a Serverless Application without a Dockerfile
75+
76+
If you hava an application without a `Dockerfile` like this [Java Application](https://github.com/buildpacks/samples/tree/main/apps/java-maven), you can also build and run your application in the serverless way like this [Java application](https://github.com/OpenFunction/samples/tree/main/apps/buildpacks/java):
77+
78+
1. Create the sample Java serverless app
79+
80+
```shell
81+
cat <<EOF | kubectl apply -f -
82+
apiVersion: core.openfunction.io/v1beta1
83+
kind: Function
84+
metadata:
85+
name: sample-java-app-buildpacks
86+
spec:
87+
version: "v1.0.0"
88+
image: "openfunction/sample-java-app-buildpacks:v1"
89+
imageCredentials:
90+
name: push-secret
91+
port: 8080 # default to 8080
92+
build:
93+
builder: "cnbs/sample-builder:alpine"
94+
srcRepo:
95+
url: "https://github.com/buildpacks/samples.git"
96+
sourceSubPath: "apps/java-maven"
97+
revision: "main"
98+
serving:
99+
runtime: "knative" # default to knative
100+
template:
101+
containers:
102+
- name: function
103+
imagePullPolicy: IfNotPresent
104+
EOF
105+
```
106+
107+
2. Check the serverless app status
108+
109+
You can then check the serverless app's status by `kubectl get functions.core.openfunction.io -w`:
110+
111+
```shell
112+
kubectl get functions.core.openfunction.io -w
113+
NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
114+
sample-java-app-buildpacks Succeeded Running builder-jgnzp serving-q6wdp http://sample-java-app-buildpacks.default.svc.cluster.local/ 22m
115+
```
116+
117+
3. Access the function
118+
119+
Once the `BUILDSTATE` becomes `Succeeded` and the `SERVINGSTATE` becomes `Running`, you can access this Java serverless app through the address in the `ADDRESS` field:
120+
121+
```shell
122+
kubectl run curl --image=radial/busyboxplus:curl -i --tty
123+
curl http://sample-java-app-buildpacks.default.svc.cluster.local
124+
```

content/en/docs/getting-started/Quickstarts/async-functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Create async functions"
3-
linkTitle: "Create async functions"
2+
title: "Create Async Functions"
3+
linkTitle: "Create Async Functions"
44
weight: 2230
55
description:
66
---
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "Create Serverless Applications"
3+
linkTitle: "Create Serverless Applications"
4+
weight: 2240
5+
description:
6+
---
7+
8+
> Before you creating any functions, make sure you've installed all the [prerequisites](../prerequisites)
9+
10+
In addition to building and running Serverless Functions, you can also build and run Serverless Applications with OpenFuntion.
11+
12+
Here you can find several Serverless Application examples:
13+
14+
| | Serverless Applications |
15+
|-----------|-----------------|
16+
| Go | [Go App with a Dockerfile](https://github.com/OpenFunction/samples/tree/main/apps/buildah/go) |
17+
| Java | [Java App with a Dockerfile](https://github.com/OpenFunction/samples/tree/main/apps/buildah/java), [Java App without a Dockerfile](https://github.com/OpenFunction/samples/blob/main/apps/buildpacks/java/sample-java-app-buildpacks.yaml) & [Source Code](https://github.com/buildpacks/samples/tree/main/apps/java-maven)|
18+
19+
> You can find more info about these Serverless Applications [here](../../../concepts/serverless_apps/)

content/en/docs/getting-started/Quickstarts/sync-functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Create sync functions"
3-
linkTitle: "Create sync functions"
2+
title: "Create Sync Functions"
3+
linkTitle: "Create Sync Functions"
44
weight: 2220
55
description:
66
---

0 commit comments

Comments
 (0)