2017-11-29 10 views
0

mongo 데이터를 유지하기 위해 kubernetes 마스터 시스템의 NFS 볼륨에 mongo /data 디렉토리를 마운트하려고합니다. 볼륨이 성공적으로 마운트 된 것을 볼 수 있지만 서브 디렉토리가 아닌 configdbdb 디렉토리 만 볼 수 있습니다. 그리고 데이터가 볼륨에 지속되지 않는 것을 봅니다. 내가 kubectl describe <my_pv> 일 때 NFS (an NFS mount that lasts the lifetime of a pod)NFS 볼륨이 kubernetes에 지속되지 않습니다

왜 그렇습니까?

은 그 진술는 Kubernetes의 문서에서 참조하십시오

를 NFS 볼륨이 기존 NFS 이 포드에 장착 될 주 (Network File System)를 할 수 있습니다. 포드가 인 경우 지워지는 emptyDir과 달리 nfs 볼륨의 내용은 보존되고 볼륨은 단지 마운트 해제되어 입니다. 즉, NFS 볼륨에 데이터가 미리 채워질 수 있으며 그 데이터는 창간에 "전달"될 수 있습니다. NFS는 일 수 있으며 여러 작성자가 동시에 마운트 할 수 있습니다.

kubernetes 버전 1.8.3을 사용하고 있습니다.

몽고-deployment.yml :

apiVersion: apps/v1beta2 
kind: Deployment 
metadata: 
    name: mongo 
    labels: 
    name: mongo 
    app: mongo 
spec: 
    replicas: 3 
    selector: 
    matchLabels: 
     name: mongo 
     app: mongo 
    template: 
    metadata: 
     name: mongo 
     labels: 
     name: mongo 
     app: mongo 
    spec: 
     containers: 
     - name: mongo 
      image: mongo:3.4.9 
      ports: 
      - name: mongo 
       containerPort: 27017 
       protocol: TCP 
      volumeMounts: 
      - name: mongovol 
       mountPath: "/data" 
     volumes: 
     - name: mongovol 
     persistentVolumeClaim: 
      claimName: mongo-pvc 

몽고-pv.yml :

apiVersion: v1 
kind: PersistentVolume 
metadata: 
    name: mongo-pv 
    labels: 
    type: NFS 
spec: 
    capacity: 
    storage: 5Gi 
    accessModes: 
    - ReadWriteMany 
    persistentVolumeReclaimPolicy: Retain 
    storageClassName: slow 
    mountOptions: 
    - hard 
    - nfsvers=4.1 
    nfs: 
    path: "/mongodata" 
    server: 172.20.33.81 

몽고-pvc.yml : 내 NFS 공유를 탑재

apiVersion: v1 
kind: PersistentVolumeClaim 
metadata: 
    name: mongo-pvc 
spec: 
    accessModes: 
    - ReadWriteMany 
    resources: 
    requests: 
     storage: 3Gi 
    storageClassName: slow 
    selector: 
    matchLabels: 
     type: NFS 

방법 내 kubernetes 마스터 컴퓨터에 :

1) apt-get install nfs-kernel-server 
2) mkdir /mongodata 
3) chown nobody:nogroup -R /mongodata 
4) vi /etc/exports 
5) added the line "/mongodata *(rw,sync,all_squash,no_subtree_check)" 
6) exportfs -ra 
7) service nfs-kernel-server restart 
8) showmount -e ----> shows the share 

내 창 bash에 로그인했는데 디렉토리가 올바르게 마운트되어 있지만 데이터가 내 nfs 서버 (kubernetes master machine)에 저장되지 않습니다.

내가 여기서 뭘 잘못하고 있는지 보도록 도와주세요.

답변

0

포드에는 파일 및 디렉토리를 만들 수있는 권한이 없을 수 있습니다. 포드에 exec을 넣고 허가를 얻지 못하면 파일 시스템에 대한 허가를 완화 할 수 있고 exports 파일에 쓰기 권한을 허용하면 NFS 공유에있는 파일 touch을 시도 할 수 있습니다.

PV 객체에 GID을 지정하여 권한 거부 문제를 피할 수 있습니다. https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#access-control