├── Chart.yaml ├── LICENSE ├── README.md ├── templates ├── local-storage-class.yaml └── persistent-volumes.yaml └── values.yaml /Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | name: docker-kubernetes-pv-local-storage 3 | description: This chart lets you create a local storage class and persistent volumes for a local Kubernetes cluster started with Docker Desktop. 4 | version: 0.0.1 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 DevSpace 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Helm Chart: docker-kubernetes-pv-local-storage 2 | This is a Helm chart that lets you create a Kubernetes storage class for creating local persistent volumes for a local Kubernetes cluster started with Docker Desktop. 3 | 4 | ## Install 5 | 1. Make sure hostpath is not default storage class: `kubectl patch storageclass hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'` (optional) 6 | 2. Clone this repository: `git clone https://github.com/devspace-cloud/docker-kubernetes-pv-local-storage` 7 | 3. Edit the `values.yaml`, e.g. to add additional `persistentVolumes` (optional) 8 | 4. Deploy the chart to your Kubernetes cluster: `helm install --name=local-storage ./docker-kubernetes-pv-local-storage` 9 | 10 | You can check if your persistent volumes have been created by running: 11 | ```bash 12 | kubectl get pv 13 | ``` 14 | 15 | ## Add/Remove Volumes 16 | 1. Update `values.yaml` and add/remove `persistentVolumes` 17 | 2. Run `helm upgrade local-storage ./docker-kubernetes-pv-local-storage` 18 | 19 | ## Purge Persistent Volumes from Disk 20 | When you delete the Kubernetes persistent volume object, the underlying data will still be stored on your disk. To purge the data from your computer permanently, run: 21 | ```bash 22 | PV_NAME="my-local-pv-1" 23 | docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v //:/docker-vm alpine //bin/sh -c "rm -r /docker-vm/var/lib/docker/k8s-local-storage/$PV_NAME" 24 | ``` 25 | 26 | ## Uninstall 27 | ```bash 28 | helm del --purge local-storage 29 | ``` -------------------------------------------------------------------------------- /templates/local-storage-class.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: storage.k8s.io/v1 2 | kind: StorageClass 3 | metadata: 4 | name: {{ .Values.localStorageClass.name | quote }} 5 | annotations: 6 | {{- if .Values.localStorageClass.isDefault }} 7 | "storageclass.kubernetes.io/is-default-class": "true" 8 | {{- end }} 9 | reclaimPolicy: {{ .Values.localStorageClass.reclaimPolicy | quote }} 10 | provisioner: kubernetes.io/no-provisioner 11 | -------------------------------------------------------------------------------- /templates/persistent-volumes.yaml: -------------------------------------------------------------------------------- 1 | {{- range $pvIndex, $pv := .Values.persistentVolumes }} 2 | apiVersion: v1 3 | kind: PersistentVolume 4 | metadata: 5 | name: {{ $pv.name | quote }} 6 | labels: 7 | "devspace.cloud/pvName": "{{ $pv.name }}" 8 | spec: 9 | capacity: 10 | storage: {{ $pv.size }} 11 | accessModes: 12 | - ReadWriteOnce 13 | persistentVolumeReclaimPolicy: {{ $pv.reclaimPolicy }} 14 | storageClassName: {{ $.Values.localStorageClass.name | quote }} 15 | local: 16 | path: /var/lib/docker/k8s-local-storage/{{ $pv.name }} 17 | nodeAffinity: {{- toYaml $.Values.localStorageClass.nodeAffinity | nindent 4 }} 18 | --- 19 | apiVersion: batch/v1 20 | kind: Job 21 | metadata: 22 | name: "local-storage-init-{{ $pv.name }}-{{ $.Release.Revision }}" 23 | labels: 24 | "devspace.cloud/pvName": "{{ $pv.name }}" 25 | annotations: 26 | "helm.sh/hook": "pre-install,pre-upgrade" 27 | spec: 28 | template: 29 | spec: 30 | containers: 31 | - name: job 32 | image: busybox:1.28 33 | command: ['sh', '-c', 'mkdir -p /var/lib/docker/k8s-local-storage/{{ $pv.name }}'] 34 | volumeMounts: 35 | - mountPath: /var/lib/docker 36 | name: docker-dir 37 | restartPolicy: Never 38 | volumes: 39 | - name: docker-dir 40 | hostPath: 41 | path: /var/lib/docker 42 | backoffLimit: 4 43 | --- 44 | apiVersion: batch/v1 45 | kind: Job 46 | metadata: 47 | name: "local-storage-purge-{{ $pv.name }}-{{ $.Release.Revision }}" 48 | labels: 49 | "devspace.cloud/pvName": "{{ $pv.name }}" 50 | annotations: 51 | "helm.sh/hook": "post-delete" 52 | spec: 53 | template: 54 | spec: 55 | containers: 56 | - name: job 57 | image: bitnami/kubectl:1.15-debian-9 58 | command: ['sh', '-c', 'kubectl delete --ignore-not-found job,pvc -l "devspace.cloud/pvName:{{ $pv.name }}"'] 59 | restartPolicy: Never 60 | backoffLimit: 4 61 | --- 62 | {{- end }} 63 | -------------------------------------------------------------------------------- /values.yaml: -------------------------------------------------------------------------------- 1 | # StorageClass for local Kubernetes clusters 2 | localStorageClass: 3 | name: devspace-local-storage 4 | reclaimPolicy: Delete 5 | isDefault: true 6 | nodeAffinity: # default nodeAffinity for all persistent volumes 7 | required: 8 | nodeSelectorTerms: 9 | - matchExpressions: 10 | - key: kubernetes.io/hostname 11 | operator: In 12 | values: 13 | - "docker-desktop" 14 | 15 | persistentVolumes: 16 | - name: my-local-pv-1 17 | size: 50Gi 18 | reclaimPolicy: Retain 19 | - name: my-local-pv-2 20 | size: 5Gi 21 | reclaimPolicy: Retain --------------------------------------------------------------------------------