惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
U
Unit 42
WordPress大学
WordPress大学
B
Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
D
DataBreaches.Net
G
Google Developers Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19)
使用 Fluid 和 S3FS 对接 S3 存储及性能测试
微信公众号 · 2024-12-05 · via 陈少文的网站

本文使用的是 Fluid 1.0 版本,高版本的配置文件路径发生了变化,需要根据实际情况调整。

1. 制作镜像

1.1 fluid_config_init.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

import json
import os

rawStr = ""
with open("/etc/fluid/config.json", "r") as f:
    rawStr = f.readlines()

rawStr = rawStr[0]

script = """
#!/bin/sh
set -ex
MNT_TO=$targetPath

trap "umount ${MNT_TO}" SIGTERM
mkdir -p ${MNT_TO} || true
s3fs $bucket:$bucketPath $MNT_TO -o url=$url -o allow_other -f -d -o f2
echo "mounted and exit code: $?"
sleep inf
"""

obj = json.loads(rawStr)

with open("/root/.passwd-s3fs", "w") as f:
    f.write("%s:%s\n" % (obj["mounts"][0]["options"]["s3-access-key"], obj["mounts"][0]["options"]["s3-access-secret"]))

# set /root/.passwd-s3fs to be read only by owner
os.chmod("/root/.passwd-s3fs", 0o600)

bucketPath = obj["mounts"][0]["mountPoint"].lstrip("s3://").rstrip("/")
bucket = bucketPath.split("/")[0]
bucketPath = bucketPath[len(bucket):]

with open("/mount-s3.sh", "w") as f:
    f.write('targetPath="%s"\n' % obj["targetPath"])
    f.write('bucket="%s"\n' % bucket)
    f.write('bucketPath="%s"\n' % bucketPath)
    f.write('url="%s"\n' % obj["mounts"][0]["options"]["url"])
    f.write(script)

1.2 entrypoint.sh

1
2
3
4
5
6
#!/usr/bin/env bash
set +x

python /fluid_config_init.py
chmod u+x /mount-s3.sh
bash /mount-s3.sh

1.3 Dockerfile

1
2
3
4
5
6
FROM shaowenchen/runtime-ubuntu:20.04
RUN apt-get update && apt-get install -y python s3fs
COPY ./fluid_config_init.py /
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT []

1.4 构建镜像

1
2
docker build . --network=host -f Dockerfile -t shaowenchen/demo:fluid-s3fs
docker push shaowenchen/demo:fluid-s3fs

1. 挂载 S3 存储

  • 配置环境变量
1
2
3
4
export ENDPOINT=obs.ap-southeast-3.myhuaweicloud.com
export BUCKET=
export AK=
export SK=
  • 创建 Dataset
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
  name: mys3fs
spec:
  mounts:
    - mountPoint: s3://${BUCKET}/test1
      options:
        s3-access-key: ${AK}
        s3-access-secret: ${SK}
        url: https://${ENDPOINT}
EOF
  • 创建 ThinRuntimeProfile
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
  name: s3fs-profile
spec:
  fileSystemType: s3fs
  fuse:
    image: shaowenchen/demo:fluid-s3fs
    imageTag: latest
    imagePullPolicy: Always
    command:
      - "/usr/local/bin/entrypoint.sh"
EOF
  • 创建 ThinRuntime
1
2
3
4
5
6
7
8
kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntime
metadata:
  name: mys3fs-37
spec:
  profileName: s3fs-profile
EOF
  • 创建 Pod 负载
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: mys3fs
spec:
  containers:
    - name: mys3fs
      image: shaowenchen/demo:ubuntu
      volumeMounts:
        - mountPath: /data
          name: mys3fs
  volumes:
    - name: mys3fs
      persistentVolumeClaim:
        claimName: mys3fs
EOF

2. 性能测试

进入 Pod

1
kubectl exec -it mys3fs -- bash

执行

1
curl -sSL https://d.juicefs.com/install | sh -

安装 JuiceFS 客户端

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
juicefs bench --block-size 4 --big-file-size 1024  /data

Benchmark finished!
BlockSize: 4.0 MiB, BigFileSize: 1.0 GiB, SmallFileSize: 128 KiB, SmallFileCount: 100, NumThreads: 1
+------------------+-----------------+----------------+
|       ITEM       |      VALUE      |      COST      |
+------------------+-----------------+----------------+
|   Write big file |    194.80 MiB/s |    5.26 s/file |
|    Read big file |    100.50 MiB/s |   10.19 s/file |
| Write small file |     3.6 files/s | 277.70 ms/file |
|  Read small file |    51.1 files/s |  19.59 ms/file |
|        Stat file | 26301.5 files/s |   0.04 ms/file |
+------------------+-----------------+----------------+

3. 清理资源

1
2
3
kubectl delete pod mys3fs
kubectl delete thinruntime mys3fs
kubectl delete dataset mys3fs