Skip to content

Commit

Permalink
Introduce NFS server
Browse files Browse the repository at this point in the history
Signed-off-by: Lukianov Artyom <[email protected]>
  • Loading branch information
Lukianov Artyom authored and davidvossel committed Feb 19, 2018
1 parent 2457a90 commit 8faf24d
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 1 deletion.
43 changes: 43 additions & 0 deletions cluster/setup_nfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
#
# This file is part of the KubeVirt project
#
# 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.
#
# Copyright 2017 Red Hat, Inc.
#
set -ex

NFS_SHARE_DIR=/var/nfsshare

yum install -y nfs-utils

mkdir $NFS_SHARE_DIR
mkdir $NFS_SHARE_DIR/cirros
mkdir $NFS_SHARE_DIR/alpine
chmod -R 755 $NFS_SHARE_DIR
chown -R nfsnobody:nfsnobody $NFS_SHARE_DIR

echo "$NFS_SHARE_DIR 192.168.0.0/16(rw,sync,no_root_squash,no_all_squash)" >>/etc/exports

systemctl enable rpcbind nfs-server
systemctl start rpcbind nfs-server

# Fill NFS share with images
curl \
https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img \
>$NFS_SHARE_DIR/cirros/disk.img

curl \
http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/alpine-virt-3.7.0-x86_64.iso \
>$NFS_SHARE_DIR/alpine/disk.img
20 changes: 20 additions & 0 deletions cluster/vm-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kubevirt.io/v1alpha1
kind: VirtualMachine
metadata:
name: vm-pvc
spec:
terminationGracePeriodSeconds: 0
domain:
resources:
requests:
memory: 64M
devices:
disks:
- name: mydisk
volumeName: pvcvolume
disk:
dev: vda
volumes:
- name: pvcvolume
persistentVolumeClaim:
claimName: alpine-nfs-pvc
2 changes: 1 addition & 1 deletion hack/config-default.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
binaries="cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virtctl cmd/fake-qemu-process"
docker_images="cmd/virt-controller cmd/virt-launcher cmd/virt-handler images/iscsi-demo-target-tgtd images/vm-killer cmd/registry-disk-v1alpha images/cirros-registry-disk-demo images/fedora-cloud-registry-disk-demo images/alpine-registry-disk-demo"
docker_images="cmd/virt-controller cmd/virt-launcher cmd/virt-handler images/iscsi-demo-target-tgtd images/vm-killer cmd/registry-disk-v1alpha images/cirros-registry-disk-demo images/fedora-cloud-registry-disk-demo images/alpine-registry-disk-demo images/nfs-server-demo"
docker_prefix=kubevirt
docker_tag=${DOCKER_TAG:-latest}
master_ip=192.168.200.2
Expand Down
44 changes: 44 additions & 0 deletions images/nfs-server-demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# This file is part of the KubeVirt project
#
# 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.
#
# Copyright 2017 Red Hat, Inc.
#

FROM alpine:latest

MAINTAINER "The KubeVirt Project" <[email protected]>
ENV container docker

RUN apk add --no-cache nfs-utils

ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.2/s6-overlay-amd64.tar.gz /tmp/
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C /

COPY s6/config.init /etc/cont-init.d/00-config
COPY s6/rpcbind.run /etc/services.d/rpcbind/run
COPY s6/mountd.run /etc/services.d/mountd/run

RUN mkdir -p /volumes/cirros \
&& mkdir -p /volumes/alpine \
&& chmod -R 777 /volumes \
&& echo "/volumes *(rw,sync,no_root_squash,no_all_squash)" >> /etc/exports

# Fill NFS share with images
ADD https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img /volumes/cirros/disk.img
ADD http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/alpine-virt-3.7.0-x86_64.iso /volumes/alpine/disk.img

EXPOSE 111/tcp 111/udp 2049/tcp 2049/udp

CMD ["/init"]
3 changes: 3 additions & 0 deletions images/nfs-server-demo/s6/config.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv sh

exportfs -r
5 changes: 5 additions & 0 deletions images/nfs-server-demo/s6/mountd.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/execlineb -P

foreground { rpc.nfsd -N 2 -N 3 }

rpc.mountd -F -N 2 -N 3
3 changes: 3 additions & 0 deletions images/nfs-server-demo/s6/rpcbind.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv sh

rpcbind -f
130 changes: 130 additions & 0 deletions manifests/testing/nfs-server-demo.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: alpine-nfs-pvc
labels:
kubevirt.io: ""
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

selector:
matchLabels:
os: "alpine-nfs"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cirros-nfs-pvc
labels:
kubevirt.io: ""
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
selector:
matchLabels:
os: "cirros-nfs"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: alpine-nfs-pv
labels:
kubevirt.io: ""
os: "alpine-nfs"
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
nfs:
path: /volumes/alpine
server: nfs-server-demo.kube-system.svc.cluster.local
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: cirros-nfs-pv
labels:
kubevirt.io: ""
os: "cirros-nfs"
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
nfs:
path: /volumes/cirros
server: nfs-server-demo.kube-system.svc.cluster.local
---
apiVersion: v1
kind: Service
metadata:
name: nfs-server-demo
namespace: kube-system
labels:
kubevirt.io: ""
spec:
ports:
- name: nfs-server-tcp
port: 2049
targetPort: 2049
protocol: TCP
- name: nfs-server-udp
port: 2049
targetPort: 2049
protocol: UDP
- name: rpcbind-tcp
port: 111
targetPort: 111
protocol: TCP
- name: rpcbind-udp
port: 111
targetPort: 111
protocol: UDP
selector:
kubevirt.io: nfs-server-demo
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nfs-server-demo
namespace: kube-system
labels:
kubevirt.io: "nfs-server-demo"
spec:
template:
metadata:
labels:
name: nfs-server-demo
kubevirt.io: nfs-server-demo
name: nfs-server-demo
spec:
serviceAccountName: kubevirt-testing
containers:
- name: nfs-server
image: {{ docker_prefix }}/nfs-server-demo:{{ docker_tag }}
ports:
- containerPort: 111
- containerPort: 2049
volumeMounts:
- name: host
mountPath: /host
env:
- name: EXPORT_HOST_PATHS
value:
securityContext:
privileged: true
volumes:
- name: host
hostPath:
path: /

0 comments on commit 8faf24d

Please sign in to comment.