Volume
Dynamic Provisioning, StorageClass, Status, ReclaimPolicy Version 1.27 에서는 스토리지 솔루션을 Longhorn으로 대체합니다.
1. Longhorn 구축
1-1) 모든 Master/Work Node에 iscsi 설치
yum --setopt=tsflags=noscripts install -y iscsi-initiator-utils
echo "InitiatorName=$(/sbin/iscsi-iname)" > /etc/iscsi/initiatorname.iscsi
systemctl enable iscsid
systemctl start iscsid
1-2) Longhorn 설치
kubectl apply -f https://raw.githubusercontent.com/kubetm/kubetm.github.io/master/yamls/longhorn/longhorn-1.5.0.yaml
kubectl apply -f https://raw.githubusercontent.com/kubetm/kubetm.github.io/master/yamls/longhorn/longhorn-1.3.3.yaml
확인
kubectl get pods -n longhorn-system
Longhorn Replica가 너무 많이 생성되니 줄여봅니다.
kubectl scale deploy -n longhorn-system csi-attacher --replicas=1
kubectl scale deploy -n longhorn-system csi-provisioner --replicas=1
kubectl scale deploy -n longhorn-system csi-resizer --replicas=1
kubectl scale deploy -n longhorn-system csi-snapshotter --replicas=1
kubectl scale deploy -n longhorn-system longhorn-ui --replicas=1
1-3) Fast StorageClass 추가
kubectl apply -f - <<END
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast
provisioner: driver.longhorn.io
parameters:
dataLocality: disabled
fromBackup: ""
fsType: ext4
numberOfReplicas: "3"
staleReplicaTimeout: "30"
END
1-4) StorageClass 생성 확인
kubectl get storageclasses.storage.k8s.io
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
fast driver.longhorn.io Delete Immediate false 16s
longhorn (default) driver.longhorn.io Delete Immediate true 85m
1-5) Dashboard 접속을 위한 Service 수정
Service Type 변경 [ClusterIP -> NodePort]
kubectl edit svc -n longhorn-system longhorn-frontend
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
nodePort: 30705 # port 번호 추가
type: NodePort # type 변경
1-6) Longhorn Dashboard 접속
http://192.168.56.30:30705
2. Dynamic Provisioning
2-1) PersistentVolume
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-hostpath1
spec:
capacity:
storage: 1G
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/hostpath
type: DirectoryOrCreate
2-2) PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-hostpath1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
storageClassName: ""
2-3) PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-fast1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
storageClassName: "fast"
2-4) PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-default1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2G
3. PV Status, ReclaimPolicy
3-1) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod-hostpath1
spec:
nodeSelector:
kubernetes.io/hostname: k8s-node1
terminationGracePeriodSeconds: 0
containers:
- name: container
image: kubetm/init
volumeMounts:
- name: hostpath
mountPath: /mount1
volumes:
- name: hostpath
persistentVolumeClaim:
claimName: pvc-hostpath1
cd /mount1
touch file.txt
Longhorn Dashboard
http://192.168.56.30:30705
3-2) PersistentVolume
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-recycle1
spec:
persistentVolumeReclaimPolicy: Recycle
capacity:
storage: 3G
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/recycle
type: DirectoryOrCreate
3-3) PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-recycle1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3G
storageClassName: ""
3-4) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod-recycle1
spec:
nodeSelector:
kubernetes.io/hostname: k8s-node1
terminationGracePeriodSeconds: 0
containers:
- name: container
image: kubetm/init
volumeMounts:
- name: hostpath
mountPath: /mount1
volumes:
- name: hostpath
persistentVolumeClaim:
claimName: pvc-recycle1
cd /mount1
touch file.txt
kubectl
Force Deletion
kubectl delete persistentvolumeclaims pvc-fast1 --namespace=default --grace-period 0 --force
kubectl delete persistentvolume pvc-b53fd802-3919-4fb0-8c1f-02221a3e4bc0 --grace-period 0 --force
Tips
hostPath
- Recycle 정책은 /tmp/로 시작하는 Path에서만 됨
Referenece
Kubernetes
- StorageClass : https://kubernetes.io/docs/concepts/storage/storage-classes
- Dynamic Volume Provisioning : https://kubernetes.io/docs/concepts/storage/dynamic-provisioning
Others
- Longhorn : https://longhorn.io/docs/0.8.1/deploy/install/install-with-kubectl/
- Ceph : https://docs.ceph.com/docs/master/
- Glusterfs : https://github.com/gluster/gluster-kubernetes
- Persistent Storage Strategies : https://www.xenonstack.com/blog/persistent-storage