Skip to content

Commit

Permalink
Example for PersistenVolumeClaim added
Browse files Browse the repository at this point in the history
I had to modify a little the local PersitentVolume example so it works with this one and created a new Pod example that uses the pvc
  • Loading branch information
sebagomez committed Oct 2, 2020
1 parent 1986521 commit 381118b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
15 changes: 15 additions & 0 deletions PersistentVolume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@ Persistent volumes are not covered here as they require third party dependencies

https://kubernetes.io/docs/concepts/storage/persistent-volumes/
https://kubernetes.io/docs/concepts/storage/volume-snapshots/

You can test a local `PersistentVolume` and a `PersistentVolumeClaim` with the following files. (this 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 ./PersistentVolume/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 mypod :80`
14 changes: 14 additions & 0 deletions PersistentVolume/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
selector:
matchLabels:
pv: local
storageClassName: hostpath
10 changes: 6 additions & 4 deletions PersistentVolume/spec.local/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ 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
path: /Users/seba/dev/storage
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- example-node
- docker-desktop
15 changes: 15 additions & 0 deletions Pod/spec.volumes.persistentVolumeClaim/pod-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: my-pvclaim

0 comments on commit 381118b

Please sign in to comment.