# Set up Workspace Volumes in your On-premise Kubernetes Cluster

cnvrg's workspace Volumes feature enables you to use workspaces with a persistent volume and reopen closed workspaces exactly as they were shut down.

While the feature is supported natively with cloud clusters, some configuration work is required to enable it to work with on-premise clusters. This guide will explain how to set it up.

# Requirements

  • kubectl and access to the Kubernetes cluster
  • A NFS server running as part of the cluster so that the nodes can access it

# Update the exports on the NFS server

Open /etc/exports in the NFS server and add the following line:

/your/nfs/share/dir  *(rw,sync,no_subtree_check,no_root_squash)

# Install Required Packages on each Node

Each node in the Kubernetes cluster needs to have the NFS client library installed. You can install it with the following command:

    # Deploy the NFS Provisioner

    The NFS provisioner is responsible for dynamically provisioning the NFS storage for volumes.

    It consists of three parts:

    • RBAC - responsible for controlling the access
    • Deployment - the actual provisioner
    • StorageClass - describing the type of storage

    Once we have created all three, the configuration will be complete.

    # Create the RBAC

    1. Here is the required RBAC YAML file. Save the YAML to your computer as rbac.yaml:
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: nfs-client-provisioner
      namespace: "cnvrg"
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: nfs-client-provisioner-runner
    rules:
      - apiGroups: [""]
        resources: ["persistentvolumes"]
        verbs: ["get", "list", "watch", "create", "delete"]
      - apiGroups: [""]
        resources: ["persistentvolumeclaims"]
        verbs: ["get", "list", "watch", "update"]
      - apiGroups: ["storage.k8s.io"]
        resources: ["storageclasses"]
        verbs: ["get", "list", "watch"]
      - apiGroups: [""]
        resources: ["events"]
        verbs: ["create", "update", "patch"]
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: run-nfs-client-provisioner
    subjects:
      - kind: ServiceAccount
        name: nfs-client-provisioner
        namespace: "cnvrg"
    roleRef:
      kind: ClusterRole
      name: nfs-client-provisioner-runner
      apiGroup: rbac.authorization.k8s.io
    ---
    kind: Role
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: leader-locking-nfs-client-provisioner
      namespace: "cnvrg"
    rules:
      - apiGroups: [""]
        resources: ["endpoints"]
        verbs: ["get", "list", "watch", "create", "update", "patch"]
    ---
    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: leader-locking-nfs-client-provisioner
      namespace: "cnvrg"
    subjects:
      - kind: ServiceAccount
        name: nfs-client-provisioner
        namespace: "cnvrg"
    roleRef:
      kind: Role
      name: leader-locking-nfs-client-provisioner
      apiGroup: rbac.authorization.k8s.io  
    
    1. Run the following command:
    kubectl -n cnvrg apply -f rbac.yaml
    

    # Create the Deployment

    1. Here is the required deployment YAML file. Save the YAML to your computer as deployment.yaml:
    kind: Deployment
    apiVersion: apps/v1
    metadata:
      name: nfs-client-provisioner
      namespace: "cnvrg"
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nfs-client-provisioner
      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: "cnvrg.io/ifs"
                - name: NFS_SERVER
                  value: "_NAME_OR_IP_NFS_SERVER__"
                - name: NFS_PATH
                  value: "/your/nfs/share/dir"
              resources:
                limits:
                  cpu: "200m"
                  memory: "200Mi"
                requests:
                  cpu: "100m"
                  memory: "100Mi"
          volumes:
            - name: nfs-client-root
              nfs:
                server: "_NAME_OR_IP_NFS_SERVER__"
                path: "/your/nfs/share/dir"
    
    1. Edit the YAML replacing the following to values with your correct information:
      • __NAME_OR_IP_NFS_SERVER__
      • /your/nfs/share/dir
    2. Run the following command:
    kubectl -n cnvrg apply -f deployment.yaml
    

    # Create the StorageClass

    1. Here is the required StorageClass YAML file. Save the YAML to your computer as storageclass.yaml:
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: "cnvrg-nfs-storage"
      namespace: "cnvrg"
      annotations:
        storageclass.beta.kubernetes.io/is-default-class: "true"
    provisioner: "cnvrg.io/ifs"
    reclaimPolicy: Retain
    
    1. (Optional) If desired, change "true" to "false". This is relevant when the newly added NFS provisioner is not your only storage provisioner on the cluster and you do now want to set it as the default provisioner.
    2. Run the following command:
    kubectl -n cnvrg apply -f storageclass.yaml
    

    # Conclusion

    You will now have created a dynamic provisioner of the NFS and can use the workspace Volumes feature.

    Last Updated: 7/30/2020, 6:09:07 AM