Openshift 4.12.0 PV, PVC (GlusterFS) 를 이용한 Volume 추가

리눅스/OpenShift|2023. 6. 8. 14:59
반응형

GlusterFS Cluster 정보를 이용하여 Endpoint 를 작성합니다.

# vi endpoint.yaml

apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
  - addresses:
      - ip: 115.68.249.122
      - ip: 115.68.248.172
      - ip: 115.68.249.106
    ports:
      - port: 1

 

* 설명

subsets: address: ip: 는 GlusterFS 클러스터를 구성하는 서버의 실제 IP 주소여야 합니다.

subsets: ports: port: 에 입력하는 포트번호는 무시해도 됩니다.

 

작성한 yaml 파일을 적용합니다.

# oc apply -f endpoint.yaml
endpoints/glusterfs-cluster created

 

적용된 Endpoint 를 확인합니다.

# oc get ep
NAME                          ENDPOINTS                                            AGE
endpoints/glusterfs-cluster   115.68.249.122:1,115.68.248.172:1,115.68.249.106:1   12m

 

PV (Persistent Volume) 생성을 위한 yaml 파일을 작성합니다.

# vi pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-pv
spec:
  storageClassName: ""
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: /gv0
    readOnly: false
  persistentVolumeReclaimPolicy: Retain

 

storageClassName: 빈 문자열을 명시적으로 사용해야 합니다. 그렇지 않으면 기본 StorageClass 가 설정됩니다.

glusterfs: endpoints: 에는 먼저 생성했던 Endpoint 이름 입니다.

glusterfs: path: 에는 마운트할 GlusterFS 의 볼륨입니다. 앞에 슬래시를 꼭 붙여줘야 합니다. 그리고 /gv0/apple 과 같이 쿼터 적용된 디렉토리로도 마운트 가능합니다.

persistentVolumeReclaimPolicy: 의 Retain 값은 PV 가 삭제되어도 GlusterFS 내의 데이터는 삭제하지 않겠다는 뜻입니다.

작성한 yaml 파일을 적용합니다.

# oc apply -f pv.yaml

persistentvolume/glusterfs-pv created

 

Pod 와 PV 를 연결하기 위한 PVC (PersistentVolumeClaim) yaml 파일을 작성합니다.

# vi pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  volumeName: glusterfs-pv

 

작성한 yaml 파일을 적용합니다.

# oc apply -f pvc.yaml

persistentvolumeclaim/glusterfs-pvc created

 

Deployment yaml 를 작성하여 Pod 가 생성되도록 합니다.

# vi deployment_volume.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: glusterfs-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: glusterfs-pod
  template:
    metadata:
      labels:
        app: glusterfs-pod
    spec:
      securityContext:
        seccompProfile:
          type: RuntimeDefault
      containers:
      - name: glusterfs-pod
        image: default-route-openshift-image-registry.apps.az1.sysdocu.kr:5000/project412/python
        ports:
        - containerPort: 8080
          protocol: TCP
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop: ["ALL"]
          runAsNonRoot: true
        volumeMounts:
        - name: my-volume
          mountPath: /data
      volumes:
      - name: my-volume
        persistentVolumeClaim:
          claimName: glusterfs-pvc
      imagePullSecrets:
      - name: sysdocu

 

volumeMounts: mountPath: 는 Pod 내에서 마운트 될 디렉토리를 의미하며 디렉토리가 없는 경우 자동으로 생성됩니다.

작성한 yaml 파일을 적용합니다.

# oc apply -f deployment_volume.yaml

 

Pod 에 Volume 이 잘 연결되었는지 확인합니다.

# oc get pod
NAME                                    READY   STATUS        RESTARTS   AGE
glusterfs-deployment-7c45b99b7c-pstl5   1/1     Running       0          7s

 

# oc rsh glusterfs-deployment-7c45b99b7c-pstl5

$ df -h
Filesystem                Size  Used Avail Use% Mounted on
overlay                   233G   36G  197G  16% /
tmpfs                      64M     0   64M   0% /dev
tmpfs                     7.8G     0  7.8G   0% /sys/fs/cgroup
shm                        64M     0   64M   0% /dev/shm
tmpfs                     7.8G   53M  7.7G   1% /etc/passwd
115.68.249.122:/gv0   10G  135M  9.9G   2% /data
/dev/sda4                 233G   36G  197G  16% /etc/hosts
tmpfs                      15G   20K   15G   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs                     7.8G     0  7.8G   0% /proc/acpi
tmpfs                     7.8G     0  7.8G   0% /proc/scsi
tmpfs                     7.8G     0  7.8G   0% /sys/firmware

 

* 참고

마운트가 되지 않을 경우 Pod 부터 정상 가동 (Running) 되지 않습니다. 그런 경우에 GlusterFS 를 구성하는 노드가 DNS 에서 질의되지 않는 호스트명으로 되어있는지 확인해 볼 필요가 있습니다. gnode1, gnode2, gnode3 등의 호스트명으로 GlusterFS 노드가 구성 되어 있다면 worker 노드에서 마운트 하지 못하므로 모든 스케쥴링 되는 Openshift 노드 (worker node) 에 /etc/hosts 파일을 수정하여 GlusterFS 를 구성하는 노드의 IP 와 호스트명을 등록해놔야 합니다.

 

반응형

댓글()