Volume

Dynamic Provisioning, StorageClass, Status, ReclaimPolicy
Volume with PV, PVC Concept for Kubernetes.


1. 사전 구성 - StorageOS 설치 및 StorageClass 생성


Volume with StorageOS Installation for Kubernetes.

1-1) StorageOS Operator 설치

설치

kubectl apply -f https://github.com/storageos/cluster-operator/releases/download/1.5.0/storageos-operator.yaml

설치 확인

kubectl get all -n storageos-operator

Depolyment 수정

kubectl edit deployments.apps storageos-cluster-operator -n storageos-operator

spec.containers.env의 DISABLE_SCHEDULER_WEBHOOK의 Value를 true로 설정

spec:
  containers:
  - command:
    - cluster-operator
    env:
    - name: DISABLE_SCHEDULER_WEBHOOK
      value: "false"    # true 로 변경
    image: storageos/cluster-operator:1.5.0
    imagePullPolicy: IfNotPresent

관리 계정을 위한 Secret 생성 (username 및 password를 Base64문자로 만들기)

echo -n "admin" | base64
echo -n "1234" | base64

apiUsernameapiPassword 부분에 위 결과로 나온 문자 넣기

kubectl create -f - <<END
apiVersion: v1
kind: Secret
metadata:
  name: "storageos-api"
  namespace: "storageos-operator"
  labels:
    app: "storageos"
type: "kubernetes.io/storageos"
data:
  apiUsername: YWRtaW4=  # admin
  apiPassword: MTIzNA==  # 1234
END

1-2) StorageOS 설치

StorageOS 설치 트리거 생성

kubectl apply -f - <<END
apiVersion: "storageos.com/v1"
kind: StorageOSCluster
metadata:
  name: "example-storageos"
  namespace: "storageos-operator"
spec:
  secretRefName: "storageos-api" # Reference the Secret created in the previous step
  secretRefNamespace: "storageos-operator"  # Namespace of the Secret
  k8sDistro: "kubernetes"
  images:
    nodeContainer: "storageos/node:1.5.0" # StorageOS version
  resources:
    requests:
    memory: "512Mi"
END

설치 확인

kubectl get all -n storageos

Dashboard 접속을 위한 Service 수정 (방법 1)

kubectl edit service storageos -n storageos

spec에 externalIPs와 Master IP 추가

spec:
  clusterIP: 10.109.77.121
  externalIPs:     # 추가
  - 192.168.0.30   # Master IP 추가
  ports:

접속

http://192.168.0.30:5705/

Dashboard 접속을 위한 Service 수정 (방법 2)

kubectl edit service storageos -n storageos

type을 NodePort로 변경

spec:
  ports:
  - name: storageos
    port: 5705
    protocol: TCP
    targetPort: 5705
    nodePort: 30705  # port 번호 추가
  type: NodePort     # type 변경

접속

http://192.168.0.30:30705/

1-3) Default StorageClass 추가

kubectl apply -f - <<END
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default
  annotations: 
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/storageos
parameters:
  adminSecretName: storageos-api
  adminSecretNamespace: storageos-operator
  fsType: ext4
  pool: default
END

StorageClass 확인

kubectl get storageclasses.storage.k8s.io
NAME                PROVISIONER               AGE
default (default)   kubernetes.io/storageos   3s
fast                kubernetes.io/storageos   59s


2. Dynamic Provisioning


Volume with Dynamic Provisioning Practice for Kubernetes.

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


Volume with PV Status, ReclaimPolicy Practice for Kubernetes.

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

StorageOS Dashboard

http://192.168.0.30:5705/

Volume with ReclaimPolicy Recycle Practice for Kubernetes.

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


yaml


StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default
  annotations:
    # Default StorageClass로 선택 
    storageclass.kubernetes.io/is-default-class: "true" 
# 동적으로 PV생성시 PersistentVolumeReclaimPolicy 선택 (Default:Delete)
reclaimPolicy: Retain, Delete, Recycle
provisioner: kubernetes.io/storageos
# provisioner 종류에 따라 parameters의 하위 내용 다름 
parameters:                                             



kubectl


Get All Objects in Namespaces

kubectl get all -n storageos-operator

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

Others