...
Code Block |
---|
language | yml |
---|
title | nfsweb-server-rcpod.yaml |
---|
|
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: web
image: nginx
volumeMounts:
# name must match the volume name below
- name: nfs
mountPath: "/usr/share/nginx/html/"
ports:
- name: web
containerPort: 80
protocol: TCP
volumes:
- name: nfs
nfs:
# FIXME: use the right name
#server: nfs-server.default.kube.local
server: "10.101.9.169"
path: "/"
readOnly: false
|
Testing it Out
After creating our NFS server and a pod consuming it, we can use kubectl exec
to test that our NFS is working as expected:
Code Block |
---|
|
# Check the node and name of our web pod
ubuntu@mltf-master:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE IP NODE
nfs-server-wc8h6 1/1 Running 0 21m 10.244.1.4 mltf-storage0
web 1/1 Running 0 11m 10.244.3.2 mltf-storage1
# Exec into the container to test writing to the NFS
ubuntu@mltf-master:~$ kubectl exec -it web -- bash
root@web:/# cat /usr/share/nginx/html/index.html
Hello from NFS!
# Test writing to a file
root@web:/# vi /usr/share/nginx/html/pod-write
bash: vi: command not found
# No "vi" included in nginx image, so we install it
root@web:/# apt-get update && apt-get install vim
Ign:1 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Get:2 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
... ... ... ... ... ... ... ... ...
Reading state information... Done
The following additional packages will be installed:
libgpm2 vim-common vim-runtime xxd
Suggested packages:
gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
libgpm2 vim vim-common vim-runtime xxd
0 upgraded, 5 newly installed, 0 to remove and 2 not upgraded.
Need to get 6766 kB of archives.
After this operation, 31.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 xxd amd64 2:8.0.0197-4+deb9u1 [132 kB]
Get:2 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 vim-common all 2:8.0.0197-4+deb9u1 [159 kB]
... ... ... ... ... ... ... ... ...
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/editor.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/editor.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group editor) doesn't exist
# Test writing to a file
root@web:/# vi /usr/share/nginx/html/pod-write
root@web:/# cat /usr/share/nginx/html/pod-write
asdf 1234 Hello, World!
root@web:/# exit
exit
# SSH into "storage0", where our NFS server pod is running
ubuntu@mltf-master:~$ ssh 192.168.0.3
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-127-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
14 packages can be updated.
7 updates are security updates.
Last login: Mon Jun 11 16:28:49 2018 from 192.168.0.6
# Verify that the file created inside of our web pod (running on "storage1") was persisted to the NFS directory on "storage0":
ubuntu@mltf-storage0:~$ cat /data/nfs/pod-write
asdf 1234 Hello, World!
|