Kubernetes Longhorn 分布式存储部署

Kubernetes   2026-01-26 16:33   55   0  

环境配置

# 安装基础软件
apt-get install -y open-iscsi nfs-common cryptsetup dmsetup
systemctl enable open-iscsi
# 设置模块开机加载
echo "dm_snapshot" >> /etc/modules-load.d/k8s.conf
echo "dm_mirror" >> /etc/modules-load.d/k8s.conf
echo "dm_thin_pool" >> /etc/modules-load.d/k8s.conf
echo "dm_crypt" >> /etc/modules-load.d/k8s.conf
# 手动加载模块
modprobe dm_snapshot
modprobe dm_mirror
modprobe dm_thin_pool
modprobe dm_crypt
# 安装 longhorn 检测工具
curl -sSfL -o longhornctl https://github.com/longhorn/cli/releases/download/v1.10.1/longhornctl-linux-amd64
chmod +x longhornctl
# 环境检测
./longhornctl check preflight --kubeconfig=/root/.kube/config --image=proxy_image/longhorn-cli:v1.10.1
# 使用 Longhorn 命令行工具安装必备组件
./longhornctl install preflight --kubeconfig=/root/.kube/config --image=proxy_image/longhorn-cli:v1.10.1

安装 longhorn

# 下载 longhorn YAML 文件并安装
kubectl apply -f https://github.com/longhorn/longhorn/releases/download/v1.11.0-rc3/longhorn.yaml
# 生成 longhorn 登陆用户名和密码
USER=admin; PASSWORD=admin; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> auth
# 创建 longhorn 登陆 Secret
kubectl -n longhorn-system create secret generic basic-auth --from-file=auth
# Nginx-Ingress 配置
root@node00:~/kubeadm# cat longhorn-ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: longhorn-ingress
 namespace: longhorn-system
 annotations:
   nginx.ingress.kubernetes.io/auth-type: basic
   nginx.ingress.kubernetes.io/ssl-redirect: 'false'
   nginx.ingress.kubernetes.io/auth-secret: basic-auth
   nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required '
   nginx.ingress.kubernetes.io/proxy-body-size: 10000m
spec:
 ingressClassName: nginx
 rules:
 - host: longhorn.sb250.cc
   http:
     paths:
     - backend:
         service:
           name: longhorn-frontend
           port:
             number: 80
       path: /
       pathType: Prefix
# 使用 Ingress 暴露服务
root@node00:~/kubeadm# kubectl apply -f longhorn-ingress.yml



下一篇
没有了
博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。