Skip to content

Commit

Permalink
Created YAML for working Kubernetes nfs-server.
Browse files Browse the repository at this point in the history
  • Loading branch information
erik777 committed Jul 7, 2017
1 parent c17c979 commit 3248a8f
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 1 deletion.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# kubernetes-nfs-server
YAML and instructions for deploying an nfs-server in K8S

YAML and instructions for deploying an nfs-server in Kubernetes (K8S), which can then be used by your pods.

This is derived from the K8S [NFS Example](https://github.com/kubernetes/kubernetes/tree/master/examples/volumes/nfs). I could not get the PersistentVolumeClaim (PVC) to use the PersistentVolume (PV) on Google Container Engine (GKE) that is defined for the client to use an NFS share in the example. This could be a GKE issue. The sample included here demonstrates how to directly mount an NFS share via your pod's YAML, skipping the PVC/PV declarations. This method works in GKE 1.6.

This defines two storage classes, fast (ssd) and slow. This is the only YAML that is specific to GKE. You can create your own storage classes for your provider if not GKE. Or, you can just comment out the storageClassName declaration in the nfc-server-pvc.yaml.

The create-nfs-server file shows you the commands to execute, and the order, to create your nfs-server.

The last command displays the ClusterIP of your service. You will need that to add a mount to pods that
consume the NFS shares. Here is what you will add to your pod spec:

volumes:
- name: nfs
nfs:
server: <NFS_CLUSTER_IP>
path: /

This maps to /exports in your server. You can map to subfolders inside exports. But, that folder must exist already when you create your pod. Otherwise, you willyou get an rpcbind error and your pod will never run.

If you create /exports/myapp/data in your nfs-server, you can then use this path in your pod declaration:

path: /myapp/data

This introduces some configuration and maintenance to your NFS PV. Keep in mind that this PV will exist until the PVC that created it is deleted. You can safely delete your nfs-server without losing your PV so long as you don't delete your PVC.

You will probably want some sort of snapshot/backup policy for your PV as it can become the host for your pod configuration and data.

## Resizing volumes

As of 1.6, Kubernetes lacks help in this area.

You can use your provider, such as GKE, to resize the volume. You'll likely have to shell into the nfs-server container and do a resize2fs, which can be installed with "yum install e2fsprogs".

This does not update the PersistentVolumeClaim (PVC). While you can update the YAML you use to create the PVC, in Kubernetes 1.6, you cannot change the capacity of a bound PVC. Deleting and re-creating the PVC will destroy the PV, so it is not a practical option.

## Known Issues

[Hung volumes can wedge the kubelet #31272](https://github.com/kubernetes/kubernetes/issues/31272)

8 changes: 8 additions & 0 deletions create-nfs-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kubectl create -f storage-class-gce-slow.yaml
kubectl create -f storage-class-gce-fast.yaml
kubectl create -f nfs-server-pvc.yaml
kubectl create -f nfs-server-rc.yaml
kubectl create -f nfs-server-service.yaml

# You will need the ClusterIP of the nfs-server service
kubectl describe services nfs-server
11 changes: 11 additions & 0 deletions nfs-server-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nfs-server-pvc-fast
spec:
storageClassName: fast
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
33 changes: 33 additions & 0 deletions nfs-server-rc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: ReplicationController
metadata:
name: nfs-server
spec:
replicas: 1
selector:
role: nfs-server
template:
metadata:
labels:
role: nfs-server
spec:
containers:
- name: nfs-server
image: gcr.io/google_containers/volume-nfs:0.8
ports:
- name: nfs
containerPort: 2049
- name: mountd
containerPort: 20048
- name: rpcbind
containerPort: 111
securityContext:
privileged: true
volumeMounts:
- mountPath: /exports
name: nfs-export-fast
volumes:
- name: nfs-export-fast
persistentVolumeClaim:
claimName: nfs-server-pvc-fast

14 changes: 14 additions & 0 deletions nfs-server-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: Service
apiVersion: v1
metadata:
name: nfs-server
spec:
ports:
- name: nfs
port: 2049
- name: mountd
port: 20048
- name: rpcbind
port: 111
selector:
role: nfs-server
13 changes: 13 additions & 0 deletions storage-class-gce-fast.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: fast
provisioner: kubernetes.io/gce-pd
parameters:
# type: pd-standard or pd-ssd. Default: pd-standard
type: pd-ssd
# GCE zone. If neither zone nor zones is specified, volumes are generally round-robin-ed
# across all active zones where Kubernetes cluster has a node. zone and zones parameters
# must not be used at the same time.
# zones: us-central1-a, us-central1-b

13 changes: 13 additions & 0 deletions storage-class-gce-slow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: slow
provisioner: kubernetes.io/gce-pd
parameters:
# type: pd-standard or pd-ssd. Default: pd-standard
type: pd-standard
# GCE zone. If neither zone nor zones is specified, volumes are generally round-robin-ed
# across all active zones where Kubernetes cluster has a node. zone and zones parameters
# must not be used at the same time.
# zones: us-central1-a, us-central1-b

0 comments on commit 3248a8f

Please sign in to comment.