Longhorn-k8s存储

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 详细安装步骤

bash 复制代码
# 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

bash 复制代码
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

    yaml 复制代码
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: test-pvc
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: longhorn
      resources:
        requests:
          storage: 5Gi
  3. 启动 nginx 挂载验证

    yaml 复制代码
    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在线扩容一条龙体验。


相关推荐
江畔何人初1 天前
pod的定义以及创建过程
linux·运维·云原生
等什么君!1 天前
docker -数据卷技术
运维·docker·容器
花酒锄作田1 天前
Debian 13基于kubeadm和containerd部署单节点kubernetes
kubernetes·containerd·cilium
上天_去_做颗惺星 EVE_BLUE1 天前
Docker高效使用指南:从基础到实战模板
开发语言·ubuntu·docker·容器·mac·虚拟环境
Gary董1 天前
高并发的微服务架构如何设计
微服务·云原生·架构
东哥爱编程1 天前
使用Runpod进行gpu serverless推理
云原生·serverless
好好沉淀1 天前
Docker开发笔记(详解)
运维·docker·容器
Ankie Wan1 天前
cgroup(Control Group)是 Linux 内核提供的一种机制,用来“控制、限制、隔离、统计”进程对系统资源的使用。
linux·容器·cgroup·lxc
lcx_defender1 天前
【Docker】Docker部署运行nacos
运维·docker·容器
啦啦啦小石头1 天前
docker添加用户权限不使用sudo
运维·docker·容器