|
| 1 | +--- |
| 2 | +display_name: "NFS K8s Deployment" |
| 3 | +description: "Mount an NFS share to a Coder K8s workspace" |
| 4 | +icon: "../../../../.icons/folder.svg" |
| 5 | +verified: false |
| 6 | +tags: ["kubernetes", "shared-dir", "nfs"] |
| 7 | +--- |
| 8 | + |
| 9 | +# NFS K8s Deployment |
| 10 | + |
| 11 | +This template provisions a Coder workspace as a Kubernetes Deployment, with an NFS share mounted |
| 12 | +as a volume. The NFS share will synchronize the server-side files onto the client (Coder workspace) |
| 13 | +When you stop the Coder workspace and rebuild, the NFS share will be re-mounted, and the changes persisted. |
| 14 | + |
| 15 | +Note the `volume` and `volume_mount` blocks in the deployment and container spec, |
| 16 | +respectively: |
| 17 | + |
| 18 | +```terraform |
| 19 | +resource "kubernetes_deployment" "main" { |
| 20 | + spec { |
| 21 | + template { |
| 22 | + spec { |
| 23 | + container { |
| 24 | + volume_mount { |
| 25 | + mount_path = data.coder_parameter.nfs_mount_path.value # mount path in the container |
| 26 | + name = "nfs-share" |
| 27 | + } |
| 28 | + } |
| 29 | + volume { |
| 30 | + name = "nfs-share" |
| 31 | + nfs { |
| 32 | + path = data.coder_parameter.nfs_mount_path.value # path to be exported from the server |
| 33 | + server = data.coder_parameter.nfs_server.value # server IP address |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## server-side configuration |
| 43 | + |
| 44 | +1. Create an NFS mount on the server for the clients to access: |
| 45 | + |
| 46 | + ```console |
| 47 | + export NFS_MNT_PATH=/mnt/nfs_share |
| 48 | + # Create directory to shaare |
| 49 | + sudo mkdir -p $NFS_MNT_PATH |
| 50 | + # Assign UID & GIDs access |
| 51 | + sudo chown -R uid:gid $NFS_MNT_PATH |
| 52 | + sudo chmod 777 $NFS_MNT_PATH |
| 53 | + ``` |
| 54 | + |
| 55 | +1. Grant access to the client by updating the `/etc/exports` file, which |
| 56 | + controls the directories shared with remote clients. See |
| 57 | + [Red Hat's docs for more information about the configuration options](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-nfs-server-config-exports). |
| 58 | + |
| 59 | + ```console |
| 60 | + # Provides read/write access to clients accessing the NFS from any IP address. |
| 61 | + /mnt/nfs_share *(rw,sync,no_subtree_check) |
| 62 | + ``` |
| 63 | + |
| 64 | +1. Export the NFS file share directory. You must do this every time you change |
| 65 | + `/etc/exports`. |
| 66 | + |
| 67 | + ```console |
| 68 | + sudo exportfs -a |
| 69 | + sudo systemctl restart <nfs-package> |
| 70 | + ``` |
0 commit comments