kubernetes-部署longhorn

不操千曲而后晓声,观千剑而后识器。这篇文章主要讲述kubernetes-部署longhorn相关的知识,希望能为你提供帮助。
一、部署longhorn
【kubernetes-部署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
NAMEPROVISIONERRECLAIMPOLICYVOLUMEBINDINGMODEALLOWVOLUMEEXPANSIONAGE
longhorndriver.longhorn.ioDeleteImmediatetrue28s

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
NAMEREADYSTATUSRESTARTSAGE
volume-test1/1Running05m14s

root@xirang:~# kubectl get pv
NAMECAPACITYACCESS MODESRECLAIM POLICYSTATUSCLAIMSTORAGECLASSREASONAGE
pvc-19708d1d-7cef-4800-9a78-b58dabcebe152GiRWODeleteBounddefault/longhorn-volv-pvclonghorn5m14s

root@xirang:~# kubectl get pvc
NAMESTATUSVOLUMECAPACITYACCESS MODESSTORAGECLASSAGE
longhorn-volv-pvcBoundpvc-19708d1d-7cef-4800-9a78-b58dabcebe152GiRWOlonghorn5m19s

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访问








    推荐阅读