[쿠버네티스] PV 및 PVC 생성 테스트

 

 

 

 

사전 준비물

- 마운트 가능한 NAS 스토리지

 

참고링크

: https://openstack.tistory.com/132

 

[NAS] Linux NAS 서버 구축

Linux 서버에 NAS 구축 필요 준비물- NAS 사용할 디스크/dev/sdb (xfs 포맷) 1. NAS 패키지 설치yum install -y nfs-utils 2. NAS 서버 실행systemctl enable --now rpcbindsystemctl enable --now nfs-server 3. NAS 로 공유할 디렉터리

openstack.tistory.com

 

 

1. 네임스페이스 생성

 

vi my-web-namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: my-web

 

1.1 네임스페이스 생성 및 확인

kubectl apply -f my-web-namespace.yaml
kubectl get namespaces

 

 

2. pv 생성

 

vi pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs-storage
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /data
    server: 'NAS 서버IP'

 

 

2.1 pv 생성 및 확인

 

kubectl apply -f pv.yaml
kubectl get pv

 

 

 

3. pvc 생성

 

vi pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
  namespace: my-web
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: nfs-storage

 

 

3.1 pvc 생성 및 확인

 

kubectl apply -f pvc.yaml
kubectl get pvc -n my-web

 

 

 

4. 생성한 pvc 마운트 테스트 

 

vi nginx-example.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: my-web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nfs-volume
          mountPath: /usr/share/nginx
      volumes:
      - name: nfs-volume
        persistentVolumeClaim:
          claimName: nfs-pvc

 

 

4.1 nginx pod 배포 및 확인

 

kubectl apply -f nginx-example.yaml
kubectl get pods -n my-web

 

 

마운트 확인

 

 

 

5. 테스트 후 리소스 정리

# nginx pod 정리
kubectl delete -f nginx-example.yaml

# pvc 정리
kubectl delete pvc nfs-pvc -n my-web
kubectl get pvc -n my-web

# pv 정리
kubectl delete -f pv.yaml
kubectl get pv

# namespace 정리
kubectl delete -f my-web-namespace.yaml