Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NFS export/import pod examples. #6350

Merged
merged 1 commit into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/nfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Example of NFS volume

See [nfs-web-pod.yaml](nfs-web-pod.yaml) for a quick example, how to use NFS volume
in a pod.

## Complete setup

The example below shows how to export a NFS share from a pod and import it
into another one.

### NFS server part

Define [NFS server pod](nfs-server-pod.yaml) and
[NFS service](nfs-server-service.yaml):

$ kubectl create -f nfs-server-pod.yaml
$ kubectl create -f nfs-server-service.yaml

The server exports `/mnt/data` directory as `/` (fsid=0). The directory contains
dummy `index.html`. Wait until the pod is running!

### NFS client

[WEB server pod](nfs-web-pod.yaml) uses the NFS share exported above as a NFS
volume and runs simple web server on it. The pod assumes your DNS is configured
and the NFS service is reachable as `nfs-server.default.kube.local`. Edit the
yaml file to supply another name or directly its IP address (use
`kubectl get services` to get it).

Define the pod:

$ kubectl create -f nfs-web-pod.yaml

Now the pod serves `index.html` from the NFS server:

$ curl http://<the container IP address>/
Hello World!
7 changes: 7 additions & 0 deletions examples/nfs/exporter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM fedora:21
MAINTAINER Jan Safranek <jsafrane@redhat.com>
EXPOSE 2049/tcp

RUN yum -y install nfs-utils && yum clean all && run_nfs /usr/local/bin/run_nfs

ENTRYPOINT ["/usr/local/bin/run_nfs"]
10 changes: 10 additions & 0 deletions examples/nfs/exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# NFS-exporter container

Inspired by https://github.com/cpuguy83/docker-nfs-server. Rewritten for
Fedora.

Serves NFS4 exports, defined on command line. At least one export must be defined!

Usage::

docker run -d --name nfs --privileged jsafrane/nfsexporter /path/to/share /path/to/share2 ...
72 changes: 72 additions & 0 deletions examples/nfs/exporter/run_nfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# Copyright 2015 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function start()
{

# prepare /etc/exports
seq=0
for i in "$@"; do
echo "$i *(rw,sync,no_root_squash,insecure,fsid=$seq)" >> /etc/exports
seq=$(($seq + 1))
echo "Serving $i"
done

# from /lib/systemd/system/proc-fs-nfsd.mount
mount -t nfsd nfds /proc/fs/nfsd

# from /lib/systemd/system/nfs-config.service
/usr/lib/systemd/scripts/nfs-utils_env.sh

# from /lib/systemd/system/nfs-mountd.service
. /run/sysconfig/nfs-utils
/usr/sbin/rpc.mountd $RPCMOUNTDARGS

# from /lib/systemd/system/nfs-server.service
. /run/sysconfig/nfs-utils
/usr/sbin/exportfs -r
/usr/sbin/rpc.nfsd -N 2 -N 3 -V 4 -V 4.1 $RPCNFSDARGS

echo "NFS started"
}

function stop()
{
echo "Stopping NFS"

# from /lib/systemd/system/nfs-server.service
/usr/sbin/rpc.nfsd 0
/usr/sbin/exportfs -au
/usr/sbin/exportfs -f

# from /lib/systemd/system/nfs-mountd.service
kill $( pidof rpc.mountd )
# from /lib/systemd/system/proc-fs-nfsd.mount
umount /proc/fs/nfsd

echo > /etc/exports
exit 0
}


trap stop TERM

start "$@"

# Ugly hack to do nothing and wait for SIGTERM
while true; do
read
done
5 changes: 5 additions & 0 deletions examples/nfs/nfs-data/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM jsafrane/nfsexporter
MAINTAINER Jan Safranek <jsafrane@redhat.com>
ADD index.html /mnt/data/index.html

ENTRYPOINT ["/usr/local/bin/run_nfs", "/mnt/data"]
7 changes: 7 additions & 0 deletions examples/nfs/nfs-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# NFS-exporter container with a file

This container exports /mnt/data with index.html in it via NFSv4. Based on
../exporter.

Available in dockerhub as
[jsafrane/nfs-data](https://registry.hub.docker.com/u/jsafrane/nfs-data/).
1 change: 1 addition & 0 deletions examples/nfs/nfs-data/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
15 changes: 15 additions & 0 deletions examples/nfs/nfs-server-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1beta3
kind: Pod
metadata:
name: nfs-server
labels:
role: nfs-server
spec:
containers:
- name: nfs-server
image: jsafrane/nfs-data
privileged: true
ports:
- name: nfs
containerPort: 2049
protocol: tcp
9 changes: 9 additions & 0 deletions examples/nfs/nfs-server-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Service
apiVersion: v1beta3
metadata:
name: nfs-server
spec:
ports:
- port: 2049
selector:
role: nfs-server
27 changes: 27 additions & 0 deletions examples/nfs/nfs-web-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# This pod imports nfs-server.default.kube.local:/ into /var/www/html
#

apiVersion: v1beta3
kind: Pod
metadata:
name: nfs-web
spec:
containers:
- name: web
image: dockerfile/nginx
ports:
- name: web
containerPort: 80
protocol: tcp
volumeMounts:
# name must match the volume name below
- name: nfs
mountPath: "/var/www/html"
volumes:
- name: nfs
nfs:
# FIXME: use the right hostname
server: nfs-server.default.kube.local
path: "/"
readOnly: false
21 changes: 0 additions & 21 deletions examples/nfs/test.yaml

This file was deleted.