diff --git a/content/posts/bare-metal-k8s-loadbalancing.md b/content/posts/bare-metal-k8s-loadbalancing.md index d6efa96..dc0fbc2 100644 --- a/content/posts/bare-metal-k8s-loadbalancing.md +++ b/content/posts/bare-metal-k8s-loadbalancing.md @@ -1,7 +1,7 @@ --- title: "Kubernetes Loadbalancing with Metal LB" date: 2020-01-02T20:57:36Z -tags: ["kubernetes", "homelab", "networking", "bare metal"] +tags: [kubernetes, homelab, networking, bare metal] draft: false --- diff --git a/content/posts/local-persistent-volume-k8s.md b/content/posts/local-persistent-volume-k8s.md new file mode 100644 index 0000000..012c91c --- /dev/null +++ b/content/posts/local-persistent-volume-k8s.md @@ -0,0 +1,76 @@ +--- +title: "How to setup a local persistent volume in kubernetes" +date: 2020-01-04T23:14:35Z +draft: false +tags: [kubernetes, configuration, storage] +--- + + +I'm running a single node kubernetes cluster and one of the first things I needed was persistent storage. To create a volume that you can mount into your containers in a pod you have to create a *PersistentVolume (PV)* and then request it with a *PersistentVolumeClaim (PVC)*. + + +Create a *PersistentVolume (PV)* object, pointing at a path on your host. Note the `spec.capacity.storage`, `spec.hostPath.path` and change these accordingly. + +```yaml +apiVersion: v1 +kind: PersistentVolume +metadata: + name: persistent-test-volume + labels: + name: persistent-test-volume +spec: + volumeMode: Filesystem + storageClassName: standard + accessModes: + - ReadWriteOnce # type of access + capacity: + storage: 100Gi # Size of the volume + hostPath: + path: "/storage/volumes/test-volume" +``` + +Next you must create a *PersistentVolumeClaim (PVC)* to request access to the resources of the *PersistentVolume (PV)*. + +```yaml +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: persistent-test-volume-claim +spec: + volumeMode: Filesystem + storageClassName: standard + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi + selector: + matchLabels: + name: persistent-test-volume +``` + +Now that we've set these two resources up, we can create a pod with a container that references the *PVC* we made above in the `spec.volumes` + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: pv-tester + namespace: default +spec: + restartPolicy: Never + containers: + - name: pv-tester + image: busybox + command: ["/bin/sh", "-c", "echo 'Hello volume' > /test_vol/hello.txt"] + volumeMounts: + - name: vol + mountPath: /test_vol + volumes: + - name: vol + persistentVolumeClaim: + claimName: persistent-test-volume-claim +``` + +You now should be able to see the `hello.txt` file at the path `/storage/volumes/` on the host machine. +