条件:

[root@k8s-master longhorn]# kubectl get nodes -o wide #K8S集群一个
NAME         STATUS   ROLES                  AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION           CONTAINER-RUNTIME
k8s-master   Ready    control-plane,master   27d   v1.23.8   192.168.186.128   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://24.0.2
k8s-node1    Ready    <none>                 27d   v1.23.8   192.168.186.129   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://24.0.2
k8s-node2    Ready    <none>                 27d   v1.23.8   192.168.186.130   <none>        CentOS Linux 7 (Core)   3.10.0-1160.el7.x86_64   docker://24.0.2
[root@k8s-master longhorn]# 

1. 安装基础依赖

yum install -y iscsi-initiator-utils
systemctl start    iscsid
systemctl enable  iscsid
# 数据存储文件夹
mkdir -p /data/longhorn/
chmod 777 /data/longhorn/

2.K8S-master安装helm

version=v3.3.1
curl -LO https://repo.huaweicloud.com/helm/${version}/helm-${version}-linux-amd64.tar.gz
tar -zxvf helm-${version}-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm && rm -rf linux-amd64
helm version
helm repo add longhorn https://charts.longhorn.io # 添加仓库
helm repo update # 更新仓库
[root@k8s-master longhorn]# helm version
version.BuildInfo{Version:"v3.3.1", GitCommit:"249e5215cde0c3fa72e27eb7a30e8d55c9696144", GitTreeState:"clean", GoVersion:"go1.14.7"}
[root@k8s-master longhorn]# 

3. K8S-master安装longhorn

helm install longhorn --namespace longhorn-system --create-namespace  --version 1.2.0  --set image.csi.attacher.repository=willdockerhub/csi-attacher --set image.csi.provisioner.repository=willdockerhub/csi-provisioner  --set image.csi.nodeDriverRegistrar.repository=willdockerhub/csi-node-driver-registrar  --set image.csi.resizer.repository=willdockerhub/csi-resizer  --set image.csi.snapshotter.repository=willdockerhub/csi-snapshotter  --set defaultSettings.defaultDataPath="/data/longhorn/"  --set defaultSettings.defaultReplicaCount=3  --set service.ui.type=NodePort  --set service.ui.nodePort=30890  longhorn/longhorn

4. 查看pod运行情况

kubectl get all -n longhorn-system
[root@k8s-master longhorn]# kubectl get all -n longhorn-system
NAME                                            READY   STATUS    RESTARTS      AGE
pod/csi-attacher-5545467cf-2wnnk                1/1     Running   0             19m
pod/csi-attacher-5545467cf-75ngn                1/1     Running   0             19m
pod/csi-attacher-5545467cf-fth87                1/1     Running   0             19m
pod/csi-provisioner-dbfd9989b-4nc9q             1/1     Running   0             19m
pod/csi-provisioner-dbfd9989b-d4xbr             1/1     Running   0             19m
pod/csi-provisioner-dbfd9989b-k8c4h             1/1     Running   0             19m
pod/csi-resizer-86b7bfd496-4tbln                1/1     Running   0             19m
pod/csi-resizer-86b7bfd496-qrjgc                1/1     Running   0             19m
pod/csi-resizer-86b7bfd496-scc5x                1/1     Running   0             19m
pod/csi-snapshotter-7d4cb57bd-6s9x8             1/1     Running   0             19m
pod/csi-snapshotter-7d4cb57bd-hl9tv             1/1     Running   0             19m
pod/csi-snapshotter-7d4cb57bd-zcbcq             1/1     Running   0             19m
pod/engine-image-ei-0f7c4304-p4csd              1/1     Running   0             19m
pod/engine-image-ei-0f7c4304-z6k4g              1/1     Running   0             19m
pod/instance-manager-e-1ec8217a                 1/1     Running   0             19m
pod/instance-manager-e-bb1f44bd                 1/1     Running   0             11m
pod/instance-manager-r-133281fb                 1/1     Running   0             19m
pod/instance-manager-r-2d5fe52c                 1/1     Running   0             11m
pod/longhorn-csi-plugin-5xglr                   2/2     Running   0             19m
pod/longhorn-csi-plugin-s8snr                   2/2     Running   0             19m
pod/longhorn-driver-deployer-66446cc868-dtq78   1/1     Running   0             22m
pod/longhorn-manager-9zxt9                      1/1     Running   0             22m
pod/longhorn-manager-mghw4                      1/1     Running   1 (20m ago)   22m
pod/longhorn-ui-5c5d79cd8c-5654p                1/1     Running   0             22m

NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/csi-attacher        ClusterIP   10.96.156.91    <none>        12345/TCP      19m
service/csi-provisioner     ClusterIP   10.98.174.18    <none>        12345/TCP      19m
service/csi-resizer         ClusterIP   10.97.114.120   <none>        12345/TCP      19m
service/csi-snapshotter     ClusterIP   10.97.102.105   <none>        12345/TCP      19m
service/longhorn-backend    ClusterIP   10.104.189.55   <none>        9500/TCP       22m
service/longhorn-frontend   NodePort    10.106.20.68    <none>        80:30890/TCP   22m

NAME                                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/engine-image-ei-0f7c4304   2         2         2       2            2           <none>          19m
daemonset.apps/longhorn-csi-plugin        2         2         2       2            2           <none>          19m
daemonset.apps/longhorn-manager           2         2         2       2            2           <none>          22m

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/csi-attacher               3/3     3            3           19m
deployment.apps/csi-provisioner            3/3     3            3           19m
deployment.apps/csi-resizer                3/3     3            3           19m
deployment.apps/csi-snapshotter            3/3     3            3           19m
deployment.apps/longhorn-driver-deployer   1/1     1            1           22m
deployment.apps/longhorn-ui                1/1     1            1           22m

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/csi-attacher-5545467cf                3         3         3       19m
replicaset.apps/csi-provisioner-dbfd9989b             3         3         3       19m
replicaset.apps/csi-resizer-86b7bfd496                3         3         3       19m
replicaset.apps/csi-snapshotter-7d4cb57bd             3         3         3       19m
replicaset.apps/longhorn-driver-deployer-66446cc868   1         1         1       22m
replicaset.apps/longhorn-ui-5c5d79cd8c                1         1         1       22m
[root@k8s-master longhorn]# 

5.查看默认存储器

kubectl get sc -n longhorn-system
[root@k8s-master longhorn]# kubectl get sc -n longhorn-system
NAME                 PROVISIONER          RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
longhorn (default)   driver.longhorn.io   Delete          Immediate           true                   20m
[root@k8s-master longhorn]# 

6. 登陆管理界面

kubectl get svc -n longhorn-system|grep longhorn #查看到端口
[root@k8s-master longhorn]# kubectl get svc -n longhorn-system|grep longhorn #查看到端口
longhorn-backend    ClusterIP   10.104.189.55   <none>        9500/TCP       23m
longhorn-frontend   NodePort    10.106.20.68    <none>        80:30890/TCP   23m
[root@k8s-master longhorn]# 

http://ip:30890 #端口是上面查询到的,IP是k8s集群中任何一个ip

在这里插入图片描述
使用方面自己研究吧,这里就不介绍了。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐