본문으로 건너뛰기

마운트

Virtual Machine 인스턴스와 Kubernetes Engine의 볼륨에 File Storage 인스턴스를 마운트하여 사용할 수 있습니다.

Virtual Machine 인스턴스에 마운트하기

Virtual Machine 인스턴스에 마운트하는 방법은 다음과 같습니다.

Virtual Machine 인스턴스에 연결하기

  1. 카카오클라우드 콘솔 > Beyond Compute Service > Virtual Machine 메뉴로 이동합니다.

  2. 인스턴스 메뉴에서 마운트 할 인스턴스의 [더보기] 아이콘 > SSH 연결을 선택합니다.

  3. SSH 연결 팝업창에서 [복사] 버튼을 클릭해 실행 명령어를 복사합니다.

  4. 실행 명령어를 사용해 인스턴스에 연결합니다. SSH를 사용한 인스턴스 연결에 대한 자세한 설명은 Virtual Machine > 인스턴스 생성 및 연결을 참고하시기 바랍니다.

NFS 패키지 설치하기

  1. 인스턴스의 OS를 확인한 후, 다음 명령어에 따라 NFS 패키지를 설치합니다.

    CentOS
    sudo yum install -y nfs-utils
  2. 설치가 성공적으로 완료되었는지 확인합니다.

NFS 마운트하기

  1. Virtual Machine 인스턴스에 접속하여 NFS 마운트 디렉터리를 생성합니다.

    NFS 마운트 디렉터리
    mkdir {마운트 디렉터리 이름 생성}
  2. 마운트 디렉터리의 생성 여부를 확인하기 위한 명령어를 입력합니다.

    마운트 디렉터리의 생성 여부 확인 명령어
    ls -la
  3. 다음과 같이 nfs-mount 디렉터리가 생성된 것을 확인합니다.

    디렉터리 생성 확인
    drwxr-xr-x 2 deploy deploy 4096 Dec 13 06:17 nfs-mount
  4. 인스턴스 상세 정보에서 확인할 수 있는 마운트 정보(마운트 포인트)와 생성한 마운트 디렉터리를 마운트 명령어와 함께 입력합니다.

    마운트 명령어
    sudo mount -t nfs {File Storage 인스턴스 사설 IP}:/{파일 공유 이름} {생성한 마운트 디렉터리}
  5. 마운트 여부를 확인하기 위한 명령어를 입력합니다.

    마운트 확인 명령어
    mount
  6. 다음과 같이 마운트가 성공적으로 완료되었는지 확인합니다.

    마운트 확인
    11.111.11.111:/share_storage on /home/deploy/nfs-mount type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.183.51.186,local_lock=none,addr=11.111.11.111)

NFS 마운트 해제하기

NFS 마운트 연결 해제 명령어는 다음과 같습니다.

NFS 마운트 연결 해제 명령어
umount {생성한 마운트 디렉터리}

Kubernetes Engine에 마운트하기

Kubernetes Engine에서 File Storage 인스턴스를 마운트하는 방법은 다음과 같습니다.

NFS 접근 허용하기

  1. Kubernetes Engine의 Worker Node의 IP를 확인하기 위한 명령어를 입력합니다.

    Worker Node의 IP 확인 명령어
    $ kubectl --kubeconfig={kube_config} get nodes -o wide
  2. 아래와 같이 Worker Node의 IP를 확인합니다.

    이미지. Worker Node IP 확인 Worker Node IP 확인

  3. File Storage 접근 제어 설정에서 Worker Node의 IP를 설정합니다.

    • File Storage > 인스턴스 메뉴 > 네트워크 탭 > 접근 제어 설정에서 허용된 프라이빗 IP 주소에 Worker Node IP를 설정합니다.

PV 생성하기

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

    yaml 파일 생성
    apiVersion: v1
    kind: PersistentVolume
    metadata:
    name: pv-nfs-share-storage
    spec:
    capacity:
    storage: 1Gi
    accessModes:
    - ReadWriteMany
    nfs:
    server: IP 입력
    path: /{파일 공유 이름}
    storageClassName: "nfs-share-storage"
  2. 생성한 PV yaml 파일을 Kubernetes Engine에 적용합니다.

    PV yaml 파일을 Kubernetes Engine에 적용
    $ kubectl --kubeconfig={kube_config} apply -f nfs-pv.yaml
  3. 적용 여부를 확인합니다.

    PV yaml 파일을 Kubernetes Engine에 적용 확인 명령어
    $ kubectl --kubeconfig={kube_config} get pv
  4. 다음과 같이 적용된 것을 확인할 수 있습니다.

    이미지. PV 적용 여부 확인 PV 적용 여부 확인

PVC 생성하기

  1. Persistent Volume을 포함하는 PVC(Persistent Volume Claim) yaml 파일을 생성합니다.

    PVC yaml 파일 생성
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: pvc-nfs-share-storage
    spec:
    storageClassName: "nfs-share-storage"
    accessModes:
    - ReadWriteMany
    resources:
    requests:
    storage: 1Gi
  2. PVC yaml 파일을 Kubernetes Engine에 적용합니다.

    PVC yaml 파일을 Kubernetes Engine에 적용
    $ kubectl --kubeconfig={kube_config} apply -f nfs-pvc.yaml
  3. 적용 여부를 확인하기 위한 명령어를 입력합니다.

    PVC yaml 파일을 Kubernetes Engine에 적용 확인 명령어
    $ kubectl --kubeconfig={kube_config} get pvc
  4. 다음과 같이 적용된 것을 확인할 수 있습니다.

    이미지. PV 적용 여부 확인 PV 적용 여부 확인

Deployment 생성하기

  1. Kubernetes Engine에 배포되는 Pod에 Persistent Volume Claim을 마운트하기 위해서 Deployment yaml 파일을 생성합니다.

    Deployment yaml 파일 생성
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: {Deployment 이름}
    spec:
    selector:
    matchLabels:
    app: {Label 이름}
    replicas: 2
    template:
    metadata:
    labels:
    app: {Label 이름}
    spec:
    containers:
    - name: master
    image: {사용자 컨테이너 URL}
    ports:
    - containerPort: 77
    volumeMounts:
    - mountPath: /data/share-storage
    name: pvc-volume
    volumes:
    - name: pvc-volume
    persistentVolumeClaim:
    claimName: pvc-nfs-share-storage
  2. Deployment yaml 파일을 Kubernetes Engine에 적용합니다.

    Deployment yaml 파일을 Kubernetes Engine에 적용
    $ kubectl --kubeconfig={kube_config} apply -f deployment.yaml
  3. 적용 여부를 확인하기 위한 명령어를 입력합니다.

    Deployment yaml 파일을 Kubernetes Engine에 적용 확인 명령어
    $ kubectl --kubeconfig={kube_config} get deployments
  4. 다음과 같이 적용된 것을 확인합니다.

    Deployment yaml 파일을 Kubernetes Engine에 적용 확인
    NAME         READY   UP-TO-DATE   AVAILABLE   AGE
    nginx-demo 2/2 2 2 1d
  5. Deployment에 의해 생성된 Pod를 확인하기 위한 명령어를 입력합니다.

    Pod 확인 명령어
    $ kubectl --kubeconfig={kube_config} get pods
  6. 생성한 Pod를 확인합니다.

    Pod 확인
    NAME                          READY   STATUS    RESTARTS   AGE
    nginx-demo- 1/1 Running 0 1d
    nginx-demo- 1/1 Running 0 1d

마운트 여부 확인하기

  1. 생성한 Pod에 접속합니다.

    Pod 접속
    $ kubectl --kubeconfig={kube_config} exec -it pod name /bin/bash
  2. 마운트 확인 명령어를 입력합니다.

    마운트 확인 명령어
    $ mount
  3. 마운트가 완료된 것을 확인합니다.

    마운트 확인
    ip:/share_storage on /data/share-storage type nfs4 (rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=ip,local_lock=none,addr=ip)