云原生存储之Longhorn

部署过程

初始化数据盘[可选]

pvcreate /dev/vdb /dev/vdc
vgcreate vg-longhorn /dev/vdb /dev/vdc

lvcreate -n lv-longhorn -l 100%VG vg-longhorn
mkfs.xfs /dev/vg-longhorn/lv-longhorn

mkdir -p /data/longhorn-storage
cat >> /etc/fstab <<EOF
/dev/vg-longhorn/lv-longhorn /data/longhorn-storage    xfs   defaults,noatime,nodiratime   0 0
EOF

mount -a

longhorn底层使用的是iscsi,所有需要在每台工作节点中安装iscsi软件包,

yum install -y iscsi-initiator-utils
systemctl enable --now iscsid

标记节点污点

kubectl taint nodes node-storage01 storage=longhorn:NoSchedule --overwrite  
kubectl taint nodes node-storage02 storage=longhorn:NoSchedule --overwrite
kubectl taint nodes node-storage03 storage=longhorn:NoSchedule --overwrite

以下节点配置自动创盘

kubectl label nodes node-storage01 node.longhorn.io/create-default-disk=true --overwrite
kubectl label nodes node-storage02 node.longhorn.io/create-default-disk=true --overwrite
kubectl label nodes node-storage03 node.longhorn.io/create-default-disk=true --overwrite

使用chart安装应用

helm upgrade --install longhorn \
  --namespace longhorn-system \
  --set defaultSettings.createDefaultDiskLabeledNodes=true \
  --set defaultSettings.defaultDataPath="/data/longhorn-storage/" \
  --set defaultSettings.taintToleration="storage=longhorn:NoSchedule" \
  --set defaultSettings.defaultReplicaCount=2 \
  --set service.ui.type=NodePort \
  --set service.ui.nodePort=8848 \
  http://dl.vqiu.cn/helm_chart/longhorn/longhorn-1.3.3.tgz

安装完成后,longhorn为默认StorageClass,若需要取消默认,可执行如下命令:

kubectl patch storageclass longhorn -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":""}}}'

常用运维

磁盘扩容

pvresize  /dev/vdb
lvextend -l +100%free /dev/mapper/vg--longhorn-lv--longhorn
xfs_growfs  /data/longhorn-storage

pvc空间扩容

k8s对pvc进行扩容
k8s进行pvc扩容 1.PV配置 确认pv的回收策略,十分的重要!!!!!,确认回收策略[https://kubernetes.io/zh-cn/docs/concepts...

参考引用