Home Using Persistent Storage with Kubernetes (using NFS directly)
Post
Cancel

Using Persistent Storage with Kubernetes (using NFS directly)

Using persistent storage allows the pods to share storage. The example below will mount NFS storage at “192.168.1.20:/mnt/tank/nfs”. The pod will make a claim to that NFS storage and mount it into the pod at “/usr/share/nginx/html”. The node itself does not need to mount the NFS storage itself.

Source: https://github.com/kubernetes/examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  capacity:
    storage: 1Mi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.1.20
    path: "/mnt/tank/nfs"
  mountOptions:
    - nfsvers=4.2
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 1Mi
  volumeName: nfs
---
# This pod mounts the nfs volume claim into /usr/share/nginx/html and # serves a simple web page.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-web
spec:
  replicas: 2
  selector:
    matchLabels:
      role: web-frontend
  template:
    metadata:
      labels:
        role: web-frontend
    spec:
      containers:
      - name: web
        image: nginx
        ports:
          - name: web
            containerPort: 80
        volumeMounts:
            # name must match the volume name below
            - name: nfs
              mountPath: "/usr/share/nginx/html"
      volumes:
      - name: nfs
        persistentVolumeClaim:
          claimName: nfs
This post is licensed under CC BY 4.0 by the author.