Skip to content

Commit

Permalink
Merge pull request ContainerSolutions#26 from ContainerSolutions/pvc
Browse files Browse the repository at this point in the history
Example for PersistenVolumeClaim added. Closes ContainerSolutions#18
  • Loading branch information
ianmiell authored Oct 23, 2020
2 parents b2dbac1 + 7d36de5 commit 79537df
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
8 changes: 5 additions & 3 deletions PersistentVolume/spec.local/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ apiVersion: v1
kind: PersistentVolume
metadata:
name: volumes-local-persistent-volume
labels:
pv: local
spec:
capacity:
storage: 100Gi
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
storageClassName: hostpath
local:
path: /mnt/disks/ssd1
nodeAffinity:
Expand All @@ -21,4 +23,4 @@ spec:
- key: kubernetes.io/hostname
operator: In
values:
- example-node
- docker-desktop
23 changes: 23 additions & 0 deletions PersistentVolumeClaim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
See: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims

You can test a local `PersistentVolume` and a `PersistentVolumeClaim` with the following files. (this example was tested on a docker-desktop kubernetes cluster)

1 - Create a `PersistentVolume` on your host monted on a local directory (add an `index.html` file in that directory with a hello world message)
`kubectl apply -f ./PersistentVolume/spec.local/local.yaml`

2 - Create the `PersitentVolumeClaim`
`kubectl apply -f ./PersistentVolumeClaim/pvc.yaml`

3 - Spin up a `Pod` with nginx poiting where its default root directory points to your host's directory
`kubectl apply -f ./Pod/spec.volumes.persistentVolumeClaim/pod-pvc.yaml`

4 - Port forward your `Pod` and access it with your browser. You should be able to see the `index.html` file from your local directory.
`kubectl port-forward volume-pvc :80`


Clean up
```
kubectl delete -f ./Pod/spec.volumes.persistentVolumeClaim/pod-pvc.yaml
kubectl delete -f ./PersistentVolumeClaim/pvc.yaml
kubectl delete -f ./PersistentVolume/spec.local/local.yaml
```
15 changes: 15 additions & 0 deletions PersistentVolumeClaim/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: persitent-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
selector:
matchLabels:
pv: local
storageClassName: hostpath
16 changes: 16 additions & 0 deletions Pod/spec.volumes.persistentVolumeClaim/pod-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Pod
metadata:
name: volume-pvc
spec:
containers:
- name: frontend
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: volume-pvc
volumes:
- name: volume-pvc
persistentVolumeClaim:
claimName: persitent-volume-claim

0 comments on commit 79537df

Please sign in to comment.