1 Longhorn 是什么

  • 轻量级 CNCF 分布式块存储,给 Kubernetes 提供 RWO/RWX 持久卷
  • 微服务架构:每卷 = 独立 Controller + 多副本 Replica,故障域隔离
  • 快照、备份、在线扩容、增量重建全部内置,UI 一键点到底

2 前置检查(所有节点)

组件 用途 一键脚本
open-iscsi 提供 iSCSI 挂载点 apt install open-iscsi -y && systemctl enable --now iscsid
nfs-common 备份/RWX 卷需要 apt install nfs-common -y
文件系统 ext4 / XFS 均可 mkfs.ext4 /dev/sdb 后挂到 /data
Mount propagation 已默认开启 无感

3 Helm 详细安装步骤

# 1. 添加官方仓库
helm repo add longhorn https://charts.longhorn.io
helm repo update

# 2. 创建命名空间
kubectl create namespace longhorn-system

# 3. 安装(可指定版本)
helm install longhorn longhorn/longhorn \
  --namespace longhorn-system \
  --version 1.7.3 \
  --set defaultSettings.replicaCount=3 \
  --set defaultSettings.storageOverProvisioningPercentage=200

1.7.3 适配 K8s ≥1.21;1.8+ 需 1.25+ 。


5 验证 & 访问 UI

kubectl -n longhorn-system get pod -o wide
# 所有组件 Running 后继续

# 端口转发到本地 30080
kubectl -n longhorn-system port-forward svc/longhorn-frontend 30080:80

浏览器打开 http://<任意节点IP>:30080,即可看到 Longhorn 仪表盘 。


6 功能体验

  1. 创建 StorageClass(Helm 已自带 default,也可自定义)
  2. 创建 PVC
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: test-pvc
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: longhorn
      resources:
        requests:
          storage: 5Gi
    
  3. 启动 nginx 挂载验证
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx-longhorn
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        volumeMounts:
        - name: html
          mountPath: /usr/share/nginx/html
      volumes:
      - name: html
        persistentVolumeClaim:
          claimName: test-pvc
    
  4. 在 UI 里给卷 做快照备份到 S3/NFS在线扩容一条龙体验。

更多推荐