保姆级教程:用Helm在K8s上部署RustFS对象存储(含Local Path配置与Ingress暴露)
Kubernetes实战:基于Helm与Local Path的RustFS对象存储部署指南
当企业需要构建私有化对象存储解决方案时,兼容S3协议的开源存储系统成为热门选择。本文将手把手带您完成RustFS在Kubernetes集群中的生产级部署,涵盖从底层磁盘准备到Ingress暴露的完整闭环流程。
1. 环境准备与规划
在开始部署前,我们需要对集群环境和存储架构进行周密规划。假设您已经拥有一个包含3个Worker节点和1个Master节点的Kubernetes集群(版本1.24+),每个节点配备额外的裸磁盘(如/dev/sdc)用于对象存储。
关键规划要点:
- 采用分布式部署模式,4个Pod对应16个PVC(每个Pod挂载4个卷)
- 存储节点包括所有Worker节点和Master03节点
- 使用Local Path Provisioner管理本地卷
- 通过Ingress Nginx暴露管理界面
生产环境建议为Master节点配置污点容忍,避免工作负载影响控制平面稳定性
2. 底层存储配置
2.1 磁盘格式化与挂载
首先需要在所有存储节点上准备存储目录,这里以XFS文件系统为例:
#!/bin/bash DEVICE="/dev/sdc" MOUNT_POINT="/opt/local-path-provisioner" # 检查并格式化磁盘 if ! blkid "$DEVICE" | grep -q 'TYPE="xfs"'; then mkfs.xfs -f "$DEVICE" || exit 1 fi # 配置持久化挂载 mkdir -p "$MOUNT_POINT" UUID=$(blkid -s UUID -o value "$DEVICE") grep -q "$MOUNT_POINT" /etc/fstab || echo "UUID=$UUID $MOUNT_POINT xfs defaults 0 0" >> /etc/fstab mount -a2.2 Local Path Provisioner部署
创建定制化的local-path配置:
# local-path-config.yaml apiVersion: v1 kind: ConfigMap metadata: name: local-path-config namespace: local-path-storage data: config.json: |- { "nodePathMap":[ { "node":"master03", "paths":["/opt/local-path-provisioner"] }, { "node":"worker01", "paths":["/opt/local-path-provisioner"] } ] }应用配置并验证:
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.33/deploy/local-path-storage.yaml kubectl get sc local-path -o yaml3. RustFS Helm部署
3.1 添加Helm仓库与基础配置
helm repo add rustfs https://charts.rustfs.com helm show values rustfs/rustfs > values.yaml关键配置参数说明:
| 参数 | 默认值 | 生产建议 |
|---|---|---|
| replicaCount | 1 | 4 |
| persistence.size | 10Gi | 按需调整 |
| resources.requests.memory | 256Mi | 2Gi |
| ingress.enabled | false | true |
3.2 节点调度配置
为存储节点添加标签并配置节点选择器:
kubectl label node worker01 worker02 worker03 master03 storage=rustfs在values.yaml中配置调度策略:
nodeSelector: storage: rustfs tolerations: - key: "node-role.kubernetes.io/control-plane" operator: "Exists" effect: "NoSchedule"3.3 TLS证书准备
使用cert-manager或手动创建secret:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout tls.key -out tls.crt -subj "/CN=rustfs.example.com" kubectl create secret tls rustfs-tls --cert=tls.crt --key=tls.key -n rustfs4. 高级配置与优化
4.1 存储类定制
创建专为RustFS优化的StorageClass:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: rustfs-local provisioner: rancher.io/local-path volumeBindingMode: WaitForFirstConsumer reclaimPolicy: Retain allowVolumeExpansion: true4.2 资源限制与监控
在values.yaml中配置资源限制:
resources: limits: cpu: 2 memory: 4Gi requests: cpu: 0.5 memory: 2Gi metrics: enabled: true serviceMonitor: enabled: true4.3 Ingress配置示例
ingress: enabled: true className: nginx annotations: nginx.ingress.kubernetes.io/proxy-body-size: "10G" hosts: - host: rustfs.example.com paths: - path: / pathType: Prefix tls: - secretName: rustfs-tls hosts: - rustfs.example.com5. 部署验证与故障排查
5.1 部署状态检查
# 检查Pod状态 kubectl get pods -n rustfs -o wide -l app.kubernetes.io/name=rustfs # 检查PVC绑定情况 kubectl get pvc -n rustfs # 检查Ingress配置 kubectl get ingress -n rustfs5.2 常见问题处理
问题1:Pod一直处于Pending状态
- 检查节点标签是否正确
- 验证Local Path Provisioner日志:
kubectl logs -n local-path-storage -l app=local-path-provisioner
问题2:PVC无法绑定
- 检查存储类配置
- 验证节点磁盘空间:
kubectl describe pvc <pvc-name> -n rustfs
问题3:性能不佳
- 调整XFS挂载参数:
mount -o remount,rw,noatime,nodiratime,logbufs=8 /opt/local-path-provisioner - 优化RustFS线程配置:
env: - name: RUSTFS_WORKER_THREADS value: "8"
6. 生产环境建议
在实际部署中,我们发现以下几个配置能显著提升稳定性:
- 定期维护脚本:
#!/bin/bash # 自动清理旧数据 find /opt/local-path-provisioner -type f -mtime +30 -delete- 监控告警规则示例:
- alert: RustFSVolumeUsageHigh expr: 100 * kubelet_volume_stats_used_bytes / kubelet_volume_stats_capacity_bytes > 85 for: 30m labels: severity: warning- 备份策略:
- 使用Velero进行定时备份
- 配置RustFS内置的版本控制功能
- 性能压测命令:
# 使用s3-benchmark工具测试 docker run --rm -it minio/s3-benchmark \ -a access-key -s secret-key \ -u http://rustfs-svc:9000 -b testbucket -t 16 -d 60