Skip to content

Commit cb6bf2b

Browse files
authored
Merge pull request #23 from BillyChen1/update_documentation
update doc
2 parents 443b93f + f9ce8df commit cb6bf2b

27 files changed

+4164
-4
lines changed

docs/Tutorials/Advanced/Serverless/how-to-ensure-the-completion-of-serverless-tasks.md

+95
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,98 @@ sidebar_position: 2
44
---
55

66
# How to Ensure the Completion of Serverless Tasks
7+
8+
## Background
9+
10+
In the serverless scenario, Workload such as Job, when the user container of the Pod completes the task and exits, the
11+
Fuse Sidecar can also actively exit.
12+
This enables the Job Controller to correctly determine the completion status of the Pod. However, the fuse container
13+
itself does not have an exit mechanism, and the Fluid Application Controller will detect the pods with the fluid label
14+
in the cluster.
15+
After the user container exits, the fuse container is exited normally to reach the state where the job is completed.
16+
17+
## Installation
18+
19+
You can download the latest Fluid installation package
20+
from [Fluid Releases](https://github.com/fluid-cloudnative/fluid/releases).
21+
Refer to the [Installation Documentation](/docs/get-started/installation) to complete the installation. And check that the
22+
components of Fluid are running normally (here takes JuiceFSRuntime as an example):
23+
24+
```shell
25+
$ kubectl -n fluid-system get po
26+
NAME READY STATUS RESTARTS AGE
27+
dataset-controller-86768b56fb-4pdts 1/1 Running 0 36s
28+
fluid-webhook-f77465869-zh8rv 1/1 Running 0 62s
29+
fluidapp-controller-597dbd77dd-jgsbp 1/1 Running 0 81s
30+
juicefsruntime-controller-65d54bb48f-vnzpj 1/1 Running 0 99s
31+
```
32+
33+
Typically, you will see a Pod named `dataset-controller`, a Pod named `juicefsruntime-controller`, a Pod
34+
named `fluid-webhook` and a Pod named `fluidapp-controller`.
35+
36+
## Demo
37+
38+
**Create dataset and runtime**
39+
40+
Create corresponding Runtime resources and Datasets with the same name for different types of runtimes. Take JuiceFSRuntime as an example here. For details, please refer to [Documentation](https://github.com/fluid-cloudnative/fluid/blob/master/docs/en/samples/juicefs_runtime.md), as follows:
41+
42+
```shell
43+
$ kubectl get juicefsruntime
44+
NAME WORKER PHASE FUSE PHASE AGE
45+
jfsdemo Ready Ready 2m58s
46+
$ kubectl get dataset
47+
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
48+
jfsdemo [Calculating] N/A N/A Bound 2m55s
49+
```
50+
51+
**Create Job**
52+
53+
To use Fluid in a serverless scenario, you need to add the `serverless.fluid.io/inject: "true"` label to the application pod. as follows:
54+
55+
```yaml
56+
$ cat<<EOF >sample.yaml
57+
apiVersion: batch/v1
58+
kind: Job
59+
metadata:
60+
name: demo-app
61+
spec:
62+
template:
63+
metadata:
64+
labels:
65+
serverless.fluid.io/inject: "true"
66+
spec:
67+
containers:
68+
- name: demo
69+
image: busybox
70+
args:
71+
- -c
72+
- echo $(date -u) >> /data/out.txt
73+
command:
74+
- /bin/sh
75+
volumeMounts:
76+
- mountPath: /data
77+
name: demo
78+
restartPolicy: Never
79+
volumes:
80+
- name: demo
81+
persistentVolumeClaim:
82+
claimName: jfsdemo
83+
backoffLimit: 4
84+
EOF
85+
$ kubectl create -f sample.yaml
86+
job.batch/demo-app created
87+
```
88+
89+
**Check if the Pod is completed**
90+
91+
```shell
92+
$ kubectl get job
93+
NAME COMPLETIONS DURATION AGE
94+
demo-app 1/1 14s 46s
95+
$ kubectl get po
96+
NAME READY STATUS RESTARTS AGE
97+
demo-app-wdfr8 0/2 Completed 0 25s
98+
jfsdemo-worker-0 1/1 Running 0 14m
99+
```
100+
101+
It can be seen that the job has been completed, and its pod has two containers, both of which have been completed.

docs/Tutorials/Advanced/Serverless/how-to-run-in-knative-environment.md

+284-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,287 @@ sidebar_label: How to Run in Knative Environment
33
sidebar_position: 1
44
---
55

6-
# Accelerate Data Access by MEM or SSD
6+
# How to Run in Knative Environment
7+
8+
This example uses the open source framework Knative as an example to demonstrate how to perform unified data acceleration via Fluid in a Serverless environment. This example uses AlluxioRuntime as an example, and in fact Fluid supports all Runtime running in a Serverless environment.
9+
10+
## Installation
11+
12+
1.Install Knative Serving v1.2 according to the [Knative documentation](https://knative.dev/docs/install/serving/install-serving-with-yaml/), you need to enable the [kubernetes.Deploymentspec-persistent-volume-claim](https://github.com/knative/serving/blob/main/config/core/configmaps/features.yaml#L156) option.
13+
14+
15+
Check if Knative's components are working properly
16+
17+
```
18+
kubectl get Deployments -n knative-serving
19+
```
20+
21+
> Note: This document is just for demonstration purpose, please refer to the best practices of Knative documentation for Knative deployment in production environment. Also, since the container images of Knative are in the gcr.io image repository, please make sure the images are reachable. If you are using AliCloud, you can also use [AliCloud ACK](https://help.aliyun.com/document_detail/121508.html) hosting service directly to reduce the complexity of configuring Knative.
22+
23+
2.Please refer to the [installation documentation](/docs/get-started/installation) to install the latest Fluid, and check that the Fluid components are working properly after installation (this document uses AlluxioRuntime as an example):
24+
25+
```shell
26+
$ kubectl get deploy -n fluid-system
27+
NAME READY UP-TO-DATE AVAILABLE AGE
28+
alluxioruntime-controller 1/1 1 1 18m
29+
dataset-controller 1/1 1 1 18m
30+
fluid-webhook 1/1 1 1 18m
31+
```
32+
33+
Typically, you can see a Deployment named `dataset-controller`, a Deployment named `alluxioruntime-controller`, and a Deployment named `fluid-webhook`.
34+
35+
## Configuration
36+
37+
## Running
38+
39+
**Create dataset and runtime**
40+
41+
Create Runtime resources for different types of Runtime, as well as a Dataset with the same name. Here is the example of AlluxioRuntime, the following is the Dataset content:
42+
43+
```yaml
44+
$ cat<<EOF >dataset.yaml
45+
apiVersion: data.fluid.io/v1alpha1
46+
kind: Dataset
47+
metadata:
48+
name: serverless-data
49+
spec:
50+
mounts:
51+
- mountPoint: https://mirrors.bit.edu.cn/apache/hbase/stable/
52+
name: hbase
53+
path: "/"
54+
accessModes:
55+
- ReadOnlyMany
56+
---
57+
apiVersion: data.fluid.io/v1alpha1
58+
kind: AlluxioRuntime
59+
metadata:
60+
name: serverless-data
61+
spec:
62+
replicas: 2
63+
tieredstore:
64+
levels:
65+
- mediumtype: MEM
66+
path: /dev/shm
67+
quota: 2Gi
68+
high: "0.95"
69+
low: "0.7"
70+
EOF
71+
```
72+
73+
Execute the Create Dataset operation:
74+
75+
```
76+
$ kubectl create -f dataset.yaml
77+
```
78+
79+
Check Dataset Status:
80+
81+
```shell
82+
$ kubectl get alluxio
83+
NAME MASTER PHASE WORKER PHASE FUSE PHASE AGE
84+
serverless-data Ready Ready Ready 4m52s
85+
$ kubectl get dataset
86+
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
87+
serverless-data 566.22MiB 0.00B 4.00GiB 0.0% Bound 4m52s
88+
```
89+
90+
**Creating Knative Serving Resource Objects**
91+
92+
```yaml
93+
$ cat<<EOF >serving.yaml
94+
apiVersion: serving.knative.dev/v1
95+
kind: Service
96+
metadata:
97+
name: model-serving
98+
spec:
99+
template:
100+
metadata:
101+
labels:
102+
app: model-serving
103+
serverless.fluid.io/inject: "true"
104+
annotations:
105+
autoscaling.knative.dev/target: "10"
106+
autoscaling.knative.dev/scaleDownDelay: "30m"
107+
autoscaling.knative.dev/minScale: "1"
108+
spec:
109+
containers:
110+
- image: fluidcloudnative/serving
111+
ports:
112+
- name: http1
113+
containerPort: 8080
114+
env:
115+
- name: TARGET
116+
value: "World"
117+
volumeMounts:
118+
- mountPath: /data
119+
name: data
120+
readOnly: true
121+
volumes:
122+
- name: data
123+
persistentVolumeClaim:
124+
claimName: serverless-data
125+
readOnly: true
126+
EOF
127+
$ kubectl create -f serving.yaml
128+
service.serving.knative.dev/model-serving created
129+
```
130+
131+
Please configure `serverless.fluid.io/inject: "true"` in the label of the podSpec or podTemplateSpec.
132+
133+
134+
**Check if Knative Serving is created and check if fuse-container is injected**
135+
136+
```shell
137+
$ kubectl get po
138+
NAME READY STATUS RESTARTS AGE
139+
model-serving-00001-deployment-64d674d75f-46vvf 3/3 Running 0 76s
140+
serverless-data-master-0 2/2 Running 0 16m
141+
serverless-data-worker-0 2/2 Running 0 16m
142+
serverless-data-worker-1 2/2 Running 0 16m
143+
$ kubectl get po model-serving-00001-deployment-64d674d75f-46vvf -oyaml| grep -i fluid-fuse -B 3
144+
- /opt/alluxio/integration/fuse/bin/alluxio-fuse
145+
- unmount
146+
- /runtime-mnt/alluxio/default/serverless-data/alluxio-fuse
147+
name: fluid-fuse
148+
```
149+
150+
Checking the Knative Serving startup speed, you can see that the startup data loading time is **92s**.
151+
152+
```shell
153+
$ kubectl logs model-serving-00001-deployment-64d674d75f-46vvf -c user-container
154+
Begin loading models at 16:29:02
155+
156+
real 1m32.639s
157+
user 0m0.001s
158+
sys 0m1.305s
159+
Finish loading models at 16:29:45
160+
2022-02-15 16:29:45 INFO Hello world sample started.
161+
```
162+
163+
**Clean up Knative serving instances**
164+
165+
```
166+
$ kubectl delete -f serving.yaml
167+
```
168+
169+
**Execute data warm-up**
170+
171+
Create the dataload object and check its status:
172+
173+
```yaml
174+
$ cat<<EOF >dataload.yaml
175+
apiVersion: data.fluid.io/v1alpha1
176+
kind: DataLoad
177+
metadata:
178+
name: serverless-dataload
179+
spec:
180+
dataset:
181+
name: serverless-data
182+
namespace: default
183+
EOF
184+
$ kubectl create -f dataload.yaml
185+
dataload.data.fluid.io/serverless-dataload created
186+
$ kubectl get dataload
187+
NAME DATASET PHASE AGE DURATION
188+
serverless-dataload serverless-data Complete 2m43s 34s
189+
```
190+
191+
Check the cache status at this point, the data is now fully cached in the cluster.
192+
193+
```
194+
$ kubectl get dataset
195+
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
196+
serverless-data 566.22MiB 566.22MiB 4.00GiB 100.0% Bound 33m
197+
```
198+
199+
Create Knative service again:
200+
201+
```shell
202+
$ kubectl create -f serving.yaml
203+
service.serving.knative.dev/model-serving created
204+
```
205+
206+
Checking the boot time at this point reveals that the current boot time for loading data is **3.66s**, which becomes **1/20** of the performance without warm-up.
207+
208+
209+
```
210+
kubectl logs model-serving-00001-deployment-6cb54f94d7-dbgxf -c user-container
211+
Begin loading models at 18:38:23
212+
213+
real 0m3.666s
214+
user 0m0.000s
215+
sys 0m1.367s
216+
Finish loading models at 18:38:25
217+
2022-02-15 18:38:25 INFO Hello world sample started.
218+
```
219+
220+
> Note: This example uses Knative serving. If you don't have a Knative environment, you can also experiment with Deployment.
221+
222+
```yaml
223+
apiVersion: apps/v1
224+
kind: Deployment
225+
metadata:
226+
name: model-serving
227+
spec:
228+
selector:
229+
matchLabels:
230+
app: model-serving
231+
template:
232+
metadata:
233+
labels:
234+
app: model-serving
235+
serverless.fluid.io/inject: "true"
236+
spec:
237+
containers:
238+
- image: fluidcloudnative/serving
239+
name: serving
240+
ports:
241+
- name: http1
242+
containerPort: 8080
243+
env:
244+
- name: TARGET
245+
value: "World"
246+
volumeMounts:
247+
- mountPath: /data
248+
name: data
249+
volumes:
250+
- name: data
251+
persistentVolumeClaim:
252+
claimName: serverless-data
253+
```
254+
255+
> Note: The default sidecar injection mode does not enable cached directory short-circuit reads, if you need to enable this capability, you can configure the parameter `cachedir.sidecar.fluid.io/inject` to `true` in the labels.
256+
257+
```yaml
258+
apiVersion: apps/v1
259+
kind: Deployment
260+
metadata:
261+
name: model-serving
262+
spec:
263+
selector:
264+
matchLabels:
265+
app: model-serving
266+
template:
267+
metadata:
268+
labels:
269+
app: model-serving
270+
serverless.fluid.io/inject: "true"
271+
cachedir.sidecar.fluid.io/inject: "true"
272+
spec:
273+
containers:
274+
- image: fluidcloudnative/serving
275+
name: serving
276+
ports:
277+
- name: http1
278+
containerPort: 8080
279+
env:
280+
- name: TARGET
281+
value: "World"
282+
volumeMounts:
283+
- mountPath: /data
284+
name: data
285+
volumes:
286+
- name: data
287+
persistentVolumeClaim:
288+
claimName: serverless-data
289+
```

0 commit comments

Comments
 (0)