Closed6

お試し csi driver for nfs

t_umet_ume
  • とりあえず、NFS を構築 on ubuntu 18
nfs インストール
$  apt install nfs-kernel-server nfs-common

# nfs 用のディレクトリ作成
$  mkdir /mnt/nfs
$  chown nobody:nogroup /mnt/nfs/
設定ファイル編集
$  vim /etc/exports

# IPアドレスはアクセス元のIPを指定
/mnt/nfs        192.168.0.0/16(rw,sync,fsid=0,crossmnt,no_subtree_check)
nfs再起動
$ systemctl restart nfs-server
$ systemctl status nfs-server -n0
● nfs-server.service - NFS server and services
   Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2022-11-09 17:22:19 UTC; 8s ago
  Process: 15024 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
  Process: 15022 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
  Process: 15014 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
  Process: 15045 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 15044 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 15045 (code=exited, status=0/SUCCESS)
テスト
# マウント用のディレクトリ作成
$ mkdir /tmp/test

# マウント( IP アドレスは NFS サーバのアドレス)
$ mount -t nfs4 -o soft 192.168.10.51:/mnt/nfs /tmp/test
$ df -hT /tmp/test
Filesystem             Type  Size  Used Avail Use% Mounted on
192.168.10.51:/mnt/nfs nfs    20G   17G  2.6G  87% /tmp/test

# 後片付け
$ umount /tmp/test
t_umet_ume
  • csi-driver-nfs のコードを取得してきて、helm でデプロイ
  • helm : 3.5.4
  • csi-driver-nfs:4.1.0

https://github.com/kubernetes-csi/csi-driver-nfs/tree/master/charts

deploy
$ git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
$ cd csi-driver-nfs/charts/v4.1.0/csi-driver-nfs

# deploy ( 適宜 values.yaml は修正する。今回は編集なし )
$ helm install csi-driver-nfs -n kube-system .
NAME: csi-driver-nfs
LAST DEPLOYED: Wed Nov  9 17:36:12 2022
NAMESPACE: kube-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The CSI NFS Driver is getting deployed to your cluster.

To check CSI NFS Driver pods status, please run:

  kubectl --namespace=kube-system get pods --selector="release=csi-driver-nfs" --watch

$ kubectl get deploy,ds,po -n kube-system --selector="app.kubernetes.io/name=csi-driver-nfs"
NAME                                 READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/csi-nfs-controller   1/1     1            1           4m47s

NAME                          DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
daemonset.apps/csi-nfs-node   6         6         6       6            6           kubernetes.io/os=linux   4m47s

NAME                                    READY   STATUS    RESTARTS   AGE
pod/csi-nfs-controller-f56b4b4b-72n4g   3/3     Running   0          4m46s
pod/csi-nfs-node-7tzbf                  3/3     Running   0          4m46s
pod/csi-nfs-node-9v7cz                  3/3     Running   0          4m44s
pod/csi-nfs-node-gdsh6                  3/3     Running   0          4m44s
pod/csi-nfs-node-msvvk                  3/3     Running   0          4m45s
pod/csi-nfs-node-tjl9h                  3/3     Running   0          4m45s
pod/csi-nfs-node-x2p7p                  3/3     Running   0          4m44s
t_umet_ume
  • StorageClassを作って、PVC/PV を作成する
sc.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
  server: 192.168.10.51
  share: /
reclaimPolicy: Delete
volumeBindingMode: Immediate
mountOptions:
  - nfsvers=4.1
SC作成
$ kubectl apply -f sc.yaml
storageclass.storage.k8s.io/nfs-csi created

$ kc get sc nfs-csi
NAME      PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-csi   nfs.csi.k8s.io   Delete          Immediate           false                  61s
pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-nfs-dynamic
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: nfs-csi
pvc/pv作成
$ kubectl apply -f pvc.yaml
persistentvolumeclaim/pvc-nfs-dynamic created

$ kubectl get pvc pvc-nfs-dynamic
NAME              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-nfs-dynamic   Bound    pvc-64726bd7-0111-413e-b13d-26bb3d34e545   10Gi       RWX            nfs-csi        27s

$ kubectl get pv pvc-64726bd7-0111-413e-b13d-26bb3d34e545
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                         STORAGECLASS   REASON   AGE
pvc-64726bd7-0111-413e-b13d-26bb3d34e545   10Gi       RWX            Delete           Bound    kube-system/pvc-nfs-dynamic   nfs-csi                 44s
t_umet_ume
  • Pod にマウントさせて確認してみる
pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  containers:
  - image: busybox:latest
    name: busybox
    volumeMounts:
    - mountPath: /mnt
      name: pvc-nfs-dynamic
    command:
      - sleep
      - "3600"
  volumes:
  - name: pvc-nfs-dynamic
    persistentVolumeClaim:
      claimName: pvc-nfs-dynamic
テスト
$ kubectl apply -f pod.yaml
$ kubectl get po busybox
NAME      READY   STATUS    RESTARTS   AGE
busybox   1/1     Running   0          10s

$ kubectl exec busybox -- df -hT /mnt
Filesystem           Type            Size      Used Available Use% Mounted on
192.168.10.51:/pvc-64726bd7-0111-413e-b13d-26bb3d34e545
                     nfs4           19.3G      6.9G     12.4G  36% /mnt
t_umet_ume
  • helm で簡単、軽快に動いた
  • nfs なのでの容量の制限は相変わらずできなさそう・・・
このスクラップは2022/11/10にクローズされました