Longhorn 安装

5 阅读5分钟

在控制平面节点上下载 Longhorn 环境检查脚本并运行检测

curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.5.3/scripts/environment_check.sh | bash

发现报错

[INFO]  Required dependencies 'kubectl jq mktemp sort printf' are installed.
[INFO]  All nodes have unique hostnames.
[INFO]  Waiting for longhorn-environment-check pods to become ready (1/3)...
[INFO]  Waiting for longhorn-environment-check pods to become ready (1/3)...
[INFO]  Waiting for longhorn-environment-check pods to become ready (2/3)...
[INFO]  Waiting for longhorn-environment-check pods to become ready (2/3)...
[INFO]  Waiting for longhorn-environment-check pods to become ready (2/3)...
[INFO]  Waiting for longhorn-environment-check pods to become ready (2/3)...
[INFO]  All longhorn-environment-check pods are ready (3/3).
[INFO]  MountPropagation is enabled
[INFO]  Checking kernel release...
[INFO]  Checking iscsid...
[INFO]  Checking multipathd...
[WARN]  multipathd is running on server-08
[WARN]  multipathd is running on server-07
[WARN]  multipathd is running on server-06
[INFO]  Checking packages...
[ERROR] nfs-common is not found in server-08.
[ERROR] nfs-common is not found in server-07.
[ERROR] nfs-common is not found in server-06.
[INFO]  Checking nfs client...
[INFO]  Cleaning up longhorn-environment-check pods...
[INFO]  Cleanup completed.

工作节点安装 nfs-common

# ============ 在所有节点上执行 ============
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y open-iscsi
sudo systemctl enable iscsid
sudo systemctl start iscsid

# 验证 iSCSI 服务
sudo systemctl status iscsid
# ● iscsid.service - iSCSI initiator daemon (iscsid)
#    Loaded: loaded
#    Active: active (running) ✅

# 安装 NFSv4 客户端(可选,用于 RWX 卷)

# Ubuntu/Debian
sudo apt-get install -y nfs-common

重新检测

root@server-03:~# curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.5.3/scripts/environment_check.sh | bash
[INFO]  Required dependencies 'kubectl jq mktemp sort printf' are installed.
[INFO]  All nodes have unique hostnames.
[INFO]  Waiting for longhorn-environment-check pods to become ready (0/3)...
[INFO]  All longhorn-environment-check pods are ready (3/3).
[INFO]  MountPropagation is enabled
[INFO]  Checking kernel release...
[INFO]  Checking iscsid...
[INFO]  Checking multipathd...
[WARN]  multipathd is running on server-08
[WARN]  multipathd is running on server-06
[WARN]  multipathd is running on server-07
[INFO]  Checking packages...
[INFO]  Checking nfs client...
[INFO]  Cleaning up longhorn-environment-check pods...
[INFO]  Cleanup completed.

通过 apt 安装 helm

参考 helm.sh/zh/docs/int…

通过 helm 安装 longhorn

参考 longhorn.io/docs/1.10.1…

root@server-03:~# helm repo add longhorn https://charts.longhorn.io
"longhorn" has been added to your repositories
root@server-03:~# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "longhorn" chart repository
Update Complete. ⎈Happy Helming!⎈
root@server-03:~# helm install longhorn longhorn/longhorn --namespace longhorn-system --create-namespace --version 1.10.1
I1208 16:59:25.153263   46775 warnings.go:110] "Warning: unrecognized format \"int64\""
I1208 16:59:25.157211   46775 warnings.go:110] "Warning: unrecognized format \"int64\""
I1208 16:59:25.204948   46775 warnings.go:110] "Warning: unrecognized format \"int64\""
I1208 16:59:25.236238   46775 warnings.go:110] "Warning: unrecognized format \"int64\""
NAME: longhorn
LAST DEPLOYED: Mon Dec  8 16:59:20 2025
NAMESPACE: longhorn-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Longhorn is now installed on the cluster!

Please wait a few minutes for other Longhorn components such as CSI deployments, Engine Images, and Instance Managers to be initialized.

Visit our documentation at https://longhorn.io/docs/

容器报错

longhorn-system   csi-attacher-5857549d6f-85d2g                       0/1     CrashLoopBackOff   6 (3m31s ago)   22m
longhorn-system   csi-attacher-5857549d6f-fb6n7                       1/1     Running            7 (7m36s ago)   22m
longhorn-system   csi-attacher-5857549d6f-p4zrd                       0/1     CrashLoopBackOff   6 (4m50s ago)   22m

日志

W1209 01:47:37.507371 1 logging.go:55] [core] [Channel #1 SubChannel #2]grpc: addrConn.createTransport failed to connect to {Addr: "/csi/csi.sock", ServerName: "localhost", Attributes: {"<%!p(networktype.keyType=grpc.internal.transport.networktype)>": "unix" }, BalancerAttributes: {"<%!p(pickfirstleaf.managedByPickfirstKeyType={})>": "<%!p(bool=true)>" }}. Err: connection error: desc = "transport: Error while dialing: dial unix /csi/csi.sock: connect: no such file or directory"

如果 csi-attacherlonghorn-csi-plugin 先启动,就会找不到 socket 文件。等一会自己就好了

查看部署情况

root@server-03:~# kubectl -n longhorn-system get pod
NAME                                                READY   STATUS    RESTARTS        AGE
csi-attacher-5857549d6f-85d2g                       1/1     Running   7 (8m54s ago)   27m
csi-attacher-5857549d6f-fb6n7                       1/1     Running   7 (12m ago)     27m
csi-attacher-5857549d6f-p4zrd                       1/1     Running   7 (10m ago)     27m
csi-provisioner-57f9d44448-cpbgg                    1/1     Running   6 (10m ago)     27m
csi-provisioner-57f9d44448-jc44h                    1/1     Running   7 (12m ago)     27m
csi-provisioner-57f9d44448-s8v5q                    1/1     Running   5 (10m ago)     27m
csi-resizer-547f8b9dc8-2lbtr                        1/1     Running   5 (10m ago)     27m
csi-resizer-547f8b9dc8-bjlmf                        1/1     Running   6 (9m30s ago)   27m
csi-resizer-547f8b9dc8-st2rv                        1/1     Running   6 (10m ago)     27m
csi-snapshotter-8558df8679-6lbhd                    1/1     Running   3 (8m53s ago)   27m
csi-snapshotter-8558df8679-b7qnz                    1/1     Running   5 (9m35s ago)   27m
csi-snapshotter-8558df8679-drpv6                    1/1     Running   7 (9m19s ago)   27m
engine-image-ei-3154f3aa-8fcnv                      1/1     Running   0               28m
engine-image-ei-3154f3aa-ksq88                      1/1     Running   0               28m
engine-image-ei-3154f3aa-tpc7t                      1/1     Running   0               28m
instance-manager-052b3834611151737f695f89d57fce49   1/1     Running   0               27m
instance-manager-4191a0f0f8cc163534fee833ea75fe48   1/1     Running   0               26m
instance-manager-48b270012cb83abe9f7e9abfc882a310   1/1     Running   0               27m
longhorn-csi-plugin-42klz                           3/3     Running   1 (16m ago)     27m
longhorn-csi-plugin-ghszk                           3/3     Running   1 (12m ago)     27m
longhorn-csi-plugin-gx69m                           3/3     Running   1 (19m ago)     27m
longhorn-driver-deployer-676f7f6c5c-f9l89           1/1     Running   0               8h
longhorn-manager-9tfkz                              2/2     Running   2 (28m ago)     8h
longhorn-manager-xp7nw                              2/2     Running   0               8h
longhorn-manager-zxf6p                              2/2     Running   3 (28m ago)     8h
longhorn-ui-7c54575f4d-2mcc9                        1/1     Running   0               8h
longhorn-ui-7c54575f4d-ptp4q                        1/1     Running   0               8h

配置 ingress

只能配置根路径访问,如果不是根路径的话,css 和 js 那些资源是写死访问根路径的,到时候会报 404

cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: longhorn-ingress
  namespace: longhorn-system
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: longhorn-frontend
            port:
              number: 80
EOF

报错

Error from server (InternalError): error when creating "STDIN": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": failed to call webhook: Post "https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1/ingresses?timeout=10s": EOF

把 ingress 的 ValidatingWebhook 删掉再重新创建,作用是在创建/更新 Ingress 时进行额外的验证检查,删掉只是失去了创建时的高级验证(比如检查配置语法错误),无伤大雅

root@server-03:~# kubectl delete validatingwebhookconfigurations ingress-nginx-admission
validatingwebhookconfiguration.admissionregistration.k8s.io "ingress-nginx-admission" deleted

浏览器访问 ingress 的 external-ip 看到了 longhorn web

http://192.168.174.210/#/dashboard