Skip to content

Latest commit

 

History

History

task_038__local__kind__extramounts_for_pv_and_pvc

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Learn Kind Cluster

Validate Persistent Volume Set Up using ExtraMounts

Extra mounts can be used to pass through storage on the host to a kind node for persisting data, mounting through code etc.

mkdir /tmp/kindpath
  • config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  # add a mount from /path/to/my/files on the host to /files on the node
  extraMounts:
  - hostPath: /tmp/kindpath
    containerPath: /files   
  • Create Cluster
kind create cluster --config - <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  # add a mount from /path/to/my/files on the host to /files on the node
  extraMounts:
  - hostPath: /tmp/kindpath
    containerPath: /files
EOF
  • pv.yaml : To create a persistent volume
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/kindpath"
  • pvc.yaml : To create persistent volume claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  • pod.yaml : To create a pod
apiVersion: v1
kind: Pod
metadata:
  name: local-pod
spec:
  containers:
  - name: local-container
    image: nginx
    volumeMounts:
    - name: local-volume
      mountPath: "/mnt/data"
  volumes:
  - name: local-volume
    persistentVolumeClaim:
      claimName: local-pvc
  • Apply
$ kubectl apply -f pv.yaml,pvc.yaml,pod.yaml                 
persistentvolume/local-pv created
persistentvolumeclaim/local-pvc created
pod/local-pod created
  • Validate
kubectl exec -it local-pod -- bash
root@local-pod:/# cd /mnt/data
root@local-pod:/mnt/data# ls
root@local-pod:/mnt/data# echo "hello" > test.log
root@local-pod:/mnt/data# cat test.log 
hello
root@local-pod:/mnt/data# exit
exit

## get and delete
$ kubectl get pods                  
NAME        READY   STATUS    RESTARTS   AGE
local-pod   1/1     Running   0          2m27s

$ kubectl delete pod local-pod
pod "local-pod" deleted

# Create again
$ kubectl apply -f dep.yaml                 
pod/local-pod created

# login to pod and check if file exists
kubectl exec -it local-pod -- bash
root@local-pod:/# cd /mnt/data
root@local-pod:/mnt/data# cat test.log 
hello