Skip to main content

Setup an NFS client provisioner in Kubernetes

Setup an NFS client provisioner in Kubernetes

One of the most common needs when deploying Kubernetes is the ability to use shared storage. While there are several options available, one of the most commons and easier to setup is to use an NFS server.
This post will explain how to setup a dynamic NFS client provisioner on Kubernetes, relying on an existing NFS server on your systems.

Step 1. Setup an NFS server (sample for CentOS)

First thing you will need, of course, is to have an NFS server. This can be easily achieved with some easy steps:

  • Install nfs package: yum install -y nfs-utils
  • Enable and start nfs service and rpcbind:
    systemctl enable rpcbind
    systemctl enable nfs-server
    systemctl start rpcbind
    systemctl start nfs-server

  • Create the directory that will be shared by NFS, and change the permissions:
    mkdir /var/nfsshare
    chmod -R 755 /var/nfsshare
    chown nfsnobody:nfsnobody /var/nfsshare

  •  Share the NFS directory over the network, creating the /etc/exports file:
    vi /etc/exports
    /var/nfsshare * (rw,sync,no_root_squash,no_all_squash)
  • Restart the nfs service to apply the content:
    systemctl restart nfs-server
  • Add NFS and rpcbind services to firewall:
    firewall-cmd --permanent --zone=public --add-service=nfs
    firewall-cmd --permanent --zone=public --add-service=rpcbind
    firewall-cmd --reload


    The NFS server is now ready to be used

Step 2. Install NFS client provisioner

To achieve that, we will rely on Kubernetes external storage provisioner (https://github.com/kubernetes-incubator/external-storage) . An external provisioner is a dynamic volume provisioner, whose code lives outside kubernetes code.
It relies on an StorageClass object, that defines the external provisioner instance. Then, that instance will wait for PersistentVolumeClaims asking for that specific StorageClass, and will automatically create PersistentVolumes.
In that case we are relying on NFS-client provisioner (https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client) , that will provide those volumes, relying on an existing NFS server.

In order to use that, several steps are needed:
  • Clone the external-storage repository and switch to the nfs-client folder:
    git clone https://github.com/kubernetes-incubator/external-storage
    cd external-storage/nfs-client
  • Customize the deploy/class.yaml file, to give a custom provisioner name to your instance:
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: managed-nfs-storage
    provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
    parameters:
      archiveOnDelete: "false"
  • Customize the deploy/deployment.yaml file, to specify the location and folder for your NFS server, and to give the right provisioner name:
    kind: ServiceAccount
    metadata:
      name: nfs-client-provisioner
    ---
    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: nfs-client-provisioner
    spec:
      replicas: 1
      strategy:
        type: Recreate
      template:
       metadata:
        labels:
          app: nfs-client-provisioner
       spec:
         serviceAccountName: nfs-client-provisioner
         containers:
           - name: nfs-client-provisioner
             image: quay.io/external_storage/nfs-client-provisioner:latest
             volumeMounts:
               - name: nfs-client-root
                 mountPath: /persistentvolumes
             env:
               - name: PROVISIONER_NAME
                 value: fuseim.pri/ifs
    # or choose another name, must match
               - name: NFS_SERVER
                 value: <<IP_OF_YOUR_NFS_SERVER>>
               - name: NFS_PATH
                 value: <<PATH_TO_NFS_SHARED_FOLDER>>
         volumes:
           - name: nfs-client-root
             nfs:
               server: <<IP_OF_YOUR_NFS_SERVER>>
               path: <<PATH_TO_NFS_SHARED_FOLDER>>
               apiVersion: v1
  • Create the objects into your kubernetes cluster:
    kubectl create -f deploy/rbac.yaml
    kubectl create -f deploy/class.yaml
    kubectl create -f deploy/deployment.yaml
  • To actually start testing the system, you will need to create a PersistentVolumeClaim using that StorageClass. Then you will need to create a pod that uses this PersistentVolumeClaim:
    claim.yaml
    ----------
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: test-claim
      annotations:
        volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 1Mi

    pod.yaml
    --------
    kind: Pod

    apiVersion: v1
    metadata:
      name: test-pod
    spec:
      containers:
       - name: test-pod
         image: gcr.io/google_containers/busybox:1.24
         command:
           - "/bin/sh"
         args:
           - "-c"
           - "touch /mnt/SUCCESS && exit 0 || exit 1"
         volumeMounts:
           - name: nfs-pvc
             mountPath: "/mnt"
    restartPolicy: "Never"
    volumes:
       - name: nfs-pvc
         persistentVolumeClaim:
           claimName: test-claim


    kubectl create -f deploy/claim.yaml
    kubectl create -f deploy/pod.yaml
    You can see that the pods can be started now with NFS volumes that are dynamically provisioned, relying on your existing NFS server installation.

Comments

  1. I've got a great kubernetes interview guide here

    ReplyDelete
  2. Few people are very much confused to make a clear picture of machine learning in their mind. This is the reason why they have different opinions for machine learning in both good and bad sense. Now it all depends upon machine learning development services and their output.

    ReplyDelete
  3. I wish to show thanks to you just for bailing me out of this particular trouble. As a result of checking through the net and meeting techniques that were not productive, Same as your blog I found another one Inbounce Marketing .Actually I was looking for the same information on internet for Inbounce Marketing and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for all the details.

    ReplyDelete
  4. Microsoft Office 365 ProPlus is now available for free to download and install for students and . Yes, this is a full version of Office available on PC. https://crackdj.com/microsoft-office-2019-download-free/

    ReplyDelete
  5. This is completely powerful software that helps it’s users in mainstream. The features of Windows 8 are totally amazing and they works very well. https://cyberspc.com/windows-8-crack-product-key/

    ReplyDelete
  6. Belated Birthday Wishes. May all you desire come true. Happy belated birthday to you! Please forgive me for not wishing you on your special day.
    Belated Birthday Wishes

    ReplyDelete

  7. You're doing great work honing your storytelling abilities; keep it up!
    https://easyserialkeys.com/plagiarism-checker-x-crack/

    ReplyDelete

Post a Comment

Popular posts from this blog

Enable UEFI PXE boot in Supermicro SYS-E200

When provisioning my Supermicro SYS-E200-8D machines (X10 motherboard), i had the need to enable UEFI boot mode, and provision through PXE. This may seem straightforward, but there is a set of BIOS settings that need to be changed in order to enable it. First thing is to enable EFI on LAN , and enable Network Stack. To do that, enter into BIOS > Advanced > PCIe/PCI/PnP configuration and check that your settings match the following: See that PCI-E have EFI firmware loaded. Same for Onboard LAN OPROM and Onboard Video OPROM. And UEFI Network stack is enabled , as well as IPv4 PXE/IPv6 PXE support. Next thing is to modify boot settings. The usual boot order for PXE is to first add hard disk and second PXE network . The PXE tools (for example Ironic) will set a temporary boot order for PXE (one time) to enable the boot from network, but then the reboot will be done from hard disk. So be sure that your boot order matches the following: See that the first order is hard d

Test API endpoint with netcat

Do you need a simple way to validate that an API endpoint is responsive, but you don't want to use curl? There is a simple way to validate the endpoint with nc, producing an output that can be redirected to a logfile and parsed later: URL=$1 PORT=$2 while true; do     RESULT=$(nc -vz $URL $PORT 2>&1)     DATE=$(date)     echo $DATE $RESULT     sleep 1 done You can all this script with the API URL as first parameter, and API port as the second. netcat will be accessing to that endpoint and will report the results, detecting when the API is down. We also can output the date to have a reference when failures are detected. The produced output will be something like: vie jun 26 08:19:28 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds. vie jun 26 08:19:29 UTC 2020 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 192.168.111.3:6443. Ncat: 0 bytes sent, 0 bytes