I want to use data from the files present in my localsystem in my pod in k8s. How is PersistentLocalVolumes used in this and is it safe to use PersistentLocalVolumes as it is an alpha feature.
Thanks
For cluster created with kubeadm.
Add a line for KUBE_FEATURE_GATES.
Environment="KUBE_FEATURE_GATES=--feature-gates PersistentLocalVolumes=true,VolumeScheduling=true,MountPropagation=true"
Add $KUBE_FEATURE_GATES to the ExecStart line.
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CERTIFICATE_ARGS $KUBELET_EXTRA_ARGS $KUBE_FEATURE_GATES
$ cat local_pvc.yaml
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-local-pv
annotations:
"volume.alpha.kubernetes.io/node-affinity": '{
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{ "matchExpressions": [
{ "key": "kubernetes.io/hostname",
"operator": "In",
"values": ["my-node"] <--- change the node name to yours
}
]}
]}
}'
spec:
capacity:
storage: 5Gi <----- change the size to your need
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/disks/vol1 <----- change the path to yours
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: example-local-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi <----- change the size to your need
storageClassName: local-storage
----
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
Kubelet (see feature gate parameter such as PersistentLocalVolumes=true)
You can use the hostPath Volume, which will allow you to mount a directory from the host filesystem onto the POD.