In this blog post, we’ll walk through the steps to set up an NFS share on Debian and Fedora, and then use it in a Kubernetes deployment with GraphHopper. We’ll use specific Kubernetes manifests for setting up Persistent Volumes (PV), Persistent Volume Claims (PVC), and Storage Classes (SC). Finally, we’ll demonstrate how to use this NFS share in a Kubernetes deployment.
Step 1: Setting Up NFS Server
On Debian
- Install NFS server packages:
sudo apt update
sudo apt install nfs-kernel-server- Create the NFS export directory:
sudo mkdir -p /srv/nfs
sudo chown nobody:nogroup /srv/nfs
sudo chmod 777 /srv/nfs- Configure NFS exports:
Edit the/etc/exportsfile and add the following line:
/srv/nfs *(rw,sync,no_subtree_check,no_root_squash)- Export the NFS shares:
sudo exportfs -a- Start and enable the NFS server:
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-serverOn Fedora
- Install NFS server packages:
sudo dnf install nfs-utils- Create the NFS export directory:
sudo mkdir -p /srv/nfs
sudo chown nobody:nogroup /srv/nfs
sudo chmod 777 /srv/nfs- Configure NFS exports:
Edit the/etc/exportsfile and add the following line:
/srv/nfs *(rw,sync,no_subtree_check,no_root_squash)- Export the NFS shares:
sudo exportfs -a- Start and enable the NFS server:
sudo systemctl restart nfs-server
sudo systemctl enable nfs-serverStep 2: Prepare Worker Nodes
On each worker node, install the nfs-common package to ensure they can mount NFS shares:
On Debian
sudo apt update
sudo apt install nfs-commonOn Fedora
sudo dnf install nfs-utilsStep 3: Configure Kubernetes to Use NFS
We’ll use the following Kubernetes manifests to set up our NFS-backed storage.
PersistentVolume (PV)
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
path: /srv/nfs
server: ip_addressReplace ip_address with the IP address of your NFS server.
PersistentVolumeClaim (PVC)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1GiStorageClass (SC)
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: manual
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: ImmediateStep 4: Deploy GraphHopper with NFS
Here is an example snippet for your deployment.yaml to mount the NFS storage.
*here’s just a deployment part with volumes.
---
volumeMounts:
- name: nfs-storage
mountPath: "/data/"
volumes:
- name: nfs-storage
persistentVolumeClaim:
claimName: nfs-pvcStep 5: Applying the Kubernetes Manifests
Apply the manifests in the following order:
- PersistentVolume (PV):
kubectl apply -f pv.yaml- PersistentVolumeClaim (PVC):
kubectl apply -f pvc.yaml- StorageClass (SC):
kubectl apply -f sc.yaml- Deployment:
kubectl apply -f deployment.yamlGraph Data Files
Ensure that the graph data files for GraphHopper are placed in the /srv/nfs directory on your NFS server. This allows the GraphHopper container to access the data from the mounted NFS share.
