Table of Contents |
---|
...
Easy Way
Simply add hostpath to volumes section in the deployment definition:
volumes:
- name: local-vol
hostPath:
path: {{ .Values.persistentVolume.path }}
type: Directory
Example:
Code Block |
---|
kind: Deployment
apiVersion: apps/v1
metadata:
name: registry
labels:
app: registry
spec:
replicas: 1
selector:
matchLabels:
app: registry
revisionHistoryLimit: 10
template:
metadata:
labels:
app: registry
spec:
containers:
- name: registry
...
volumeMounts:
- mountPath: /var/lib/registry
name: local-vol
subPath: registry/data
volumes:
- name: local-vol
hostPath:
path: {{ .Values.persistentVolume.path }}
type: Directory
... |
Using Persistent Volume and Claim
Code Block |
---|
apiVersion: v1 kind: PersistentVolume metadata: name: local-storage spec: capacity: storage: 10Gi # volumeMode field requires BlockVolume Alpha feature gate to be enabled. volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Persist storageClassName: local-storage local: path: /var/k8s/LOCAL_STORAGE nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - k8sworker1 - k8sworker2 - k8sworker3 - docker-for-desktop --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: local-storage-claim spec: storageClassName: local-storage accessModes: - ReadWriteOnce resources: requests: storage: 3Gi |
...