...
Code Block |
---|
kind: Deployment apiVersion: apps/v1 metadata: ... spec: containers: - name: registry ... labels volumeMounts: app- mountPath: /var/lib/registry spec: name: local-vol replicas subPath: 1registry/data selector: matchLabelsvolumes: app- name: registrylocal-vol revisionHistoryLimit: 10 templatehostPath: metadata: labels:path: {{ .Values.persistentVolume.path }} app type: registry spec: containers: - name: registry ... volumeMounts: - mountPath: /var/lib/registry name: local-vol subPath: registry/data volumes:DirectoryOrCreate ... |
HostPath Storage using Persistent Volume
Define storage class and make it the default
Code Block | ||||
---|---|---|---|---|
| ||||
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: hostpath-storage
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: keystone/hostpath-storage
volumeBindingMode: Immediate
reclaimPolicy: Retain |
Remove default status from other storage classes
> kubectl patch storageclass <STORAGE_CLASS> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
Create Persistent Volumes
This example creates 10 persistent volumes using helm
Code Block | ||||
---|---|---|---|---|
| ||||
{{- $root := . -}} {{range $i, $e := until 10}} apiVersion: v1 kind: PersistentVolume metadata: name: pv-{{ $i }} spec: capacity: storage: {{ $root.Values.persistentVolume.size }} volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: hostpath-storage hostPath: path: /var/pv/pv-{{ $i }} type: DirectoryOrCreate nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname - nameoperator: local-volNotIn hostPath values: path: {{ .Values.persistentVolume- master --- {{end}} |
Make a Claim using Default Storage Class
Code Block |
---|
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: my-claim spec: storageClassName: "" accessModes: .path }} - ReadWriteOnce typeresources: DirectoryOrCreate ... requests: storage: 2Gi |
Local Storage using Persistent Volume and Claim
...