Centos7 NFS 서버설치 / k8s Persistent Volume 연결하기

Published: by Creative Commons Licence

1. Centos7 NFS 서버설치

  • NFS 패키지 다운 및 설치
# yum -y install nfs-utils rpcbind
# systemctl start rpcbind
# systemctl start nfs-server
# systemctl start rpc-statd
# systemctl enable rpcbind
# systemctl enable nfs-server
# systemctl status nfs-server
  • 공유 폴더 생성
# mkdir /share-data
# chmod 777 /share-data
  • vi /etc/exports 로 아래 내용 입력 후 저장
/share-data *(rw,sync,no_root_squash)
  • 반영
# exportfs -r
  • 방화벽 해제 및 NFS Server재시작
# systemctl stop firewalld && systemctl disable firewalld
# systemctl stop NetworkManager && systemctl disable NetworkManager
# systemctl restart nfs-server
  • work node showmount설치
# sudo yum install showmount

2. FileStroage (NFS) 연결 Pod

  • NFS 연결을 위한 PersistentVolume 생성
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nfs
  labels:
    pv: pv-nfs
spec:
  capacity:
    storage: 2G
  accessModes:
  - ReadWriteMany
  nfs:
    path: /share-data
    server: xxx.xxx.xxx.xx
  • PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-nfs
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 2G
  storageClassName: ""
  selector:
    matchLabels:
      pv: pv-nfs
  • Pod
apiVersion: v1
kind: Pod
metadata:
  name: pod-nfs
spec:
  containers:
  - name: container
    image: kubetm/init
    volumeMounts:
    - name: volume-nfs
      mountPath: /nfs/share-data
  volumes:
  - name : volume-nfs
    persistentVolumeClaim:
      claimName: pvc-nfs

참고

Storage Architecture