kubernetes-部署longhorn
Posted 南北二斗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubernetes-部署longhorn相关的知识,希望对你有一定的参考价值。
一、部署longhorn
longhorn官网:https://www.rancher.cn/longhorn
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.2.3/deploy/longhorn.yaml
kubectl get pods \\
--namespace longhorn-system \\
--watch
kubectl -n longhorn-system get pod
二、测试longhorn
1、查看storageclass
root@xirang:~# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
longhorn driver.longhorn.io Delete Immediate true 28s
2、创建pod、验证是否是pvc---->storageclass---->pv
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: longhorn-volv-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
name: volume-test
namespace: default
spec:
restartPolicy: Always
containers:
- name: volume-test
image: nginx:stable-alpine
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- ls
- /data/lost+found
initialDelaySeconds: 5
periodSeconds: 5
volumeMounts:
- name: volv
mountPath: /data
ports:
- containerPort: 80
volumes:
- name: volv
persistentVolumeClaim:
claimName: longhorn-volv-pvc
3、查看pv、pvc
root@xirang:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
volume-test 1/1 Running 0 5m14s
root@xirang:~# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-19708d1d-7cef-4800-9a78-b58dabcebe15 2Gi RWO Delete Bound default/longhorn-volv-pvc longhorn 5m14s
root@xirang:~# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
longhorn-volv-pvc Bound pvc-19708d1d-7cef-4800-9a78-b58dabcebe15 2Gi RWO longhorn 5m19s
4、查看数据存储目录,每个节点都会保存一份pvc数据的副本
[root@node02 ~]# ls /var/lib/longhorn/replicas/
pvc-19708d1d-7cef-4800-9a78-b58dabcebe15-d2569ce8
5、访问Longhorn UI
#找到拥有app=longhorn-ui标签的pod
kubectl -n longhorn-system get svc -l app=longhorn-ui
#创建service
apiVersion: v1
kind: Service
metadata:
name: longhorn-ui-svc
spec:
type: NodePort
selector:
app: longhorn-ui
ports:
- protocol: TCP
port: 80
targetPort: 8000
通过http://node_ip:nodeport访问
以上是关于kubernetes-部署longhorn的主要内容,如果未能解决你的问题,请参考以下文章
保姆级教程!手把手教你使用Longhorn管理云原生分布式SQL数据库!
揭秘 Longhorn 如何为 3.5万 个 Kubernetes 节点提供持久存储?