kubernetes tutorial | Kubernetes Volumes | Demo: create PV, PVC & Mount it a Pod using Local Storage

VSPARKZ
VSPARKZ
1.3 هزار بار بازدید - 9 ماه پیش - CERTIFIED KUBERNETES ADMINISTRATOR-------------------------------------------------------------------------Kubernetes Tutorial |
CERTIFIED KUBERNETES ADMINISTRATOR
-------------------------------------------------------------------------


Kubernetes Tutorial | DEMO Create PV PVC and Mount it in a Pod
-----------------------------------------------------------------------------------------------------------

In this video, you are going to see a DEMO on how to create PV, PVC and mount the same into the Pod.

For suggestions/feedback/doubts contact
email: [email protected]

Happy Learning !!!

===========================================================================================
USEFUL LINKS
----------------------------

Overview of Volumes

https://kubernetes.io/docs/concepts/s...

Persistent Volumes

https://kubernetes.io/docs/concepts/s...

* Kubectl Command Reference*

https://kubernetes.io/docs/reference/...


==========================================================================================
#cka #kubernetes #k8s #container



DEMO STEPS
****************

Step 1: Access & Inspect the Kubernetes Cluster

$ kubectl cluster-info

$ kubectl get nodes

$ kubectl get pods -n kube-system


Step 2: Create Persistent Volumes using Local Storage (Static Provisioning)

In Worker 1

$ mkdir -p /pv/pv-1

In Worker 2

$ mkdir -p /pv/pv-2


Create pv-1 & pv-2

Sample PV manifest
===============================================
apiVersion: v1
kind: PersistentVolume
metadata:
 name: pv-1
spec:
 accessModes:
   - ReadWriteMany
 capacity:
   storage: 1Gi
 persistentVolumeReclaimPolicy: Retain
 volumeMode: Filesystem
 local:
   path: /pv/pv-1
 nodeAffinity:
   required:
     nodeSelectorTerms:
       - matchExpressions:
           - key: kubernetes.io/hostname
             operator: In
             values:
             - worker01.kubernetes.com
================================================

Step 3: Create Persistent Volumes Claims

Create pvc-1 & pvc-2

Sample PVC Manifest
======================================

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: pvc-1
spec:
 accessModes:
   - ReadWriteMany
 volumeMode: Filesystem
 resources:
   requests:
     storage: 1Gi
=======================================


Step 4: Create Pods and Mount the Persistent Volume Claims

Create Pod-1 and Pod-2 and mount the PVC's respectively

Sample POD Manifest
===============================================
apiVersion: v1
kind: Pod
metadata:
 labels:
   app: apache
 name: pod-1
spec:
 volumes:
   - name: myvolume-1
     persistentVolumeClaim:
       claimName: pvc-1
 containers:
 - image: httpd
   name: apache
   volumeMounts:
     - name: myvolume-1
       mountPath: /usr/local/apache2/htdocs/
==================================================


Step 5: Create some data within the Pod and check the data persistence

Create some data under the mountpath folder
Since this is a webserver pod, it is suggested to create index.html for better understanding

$ kubectl exec -it pod-1 -- sh


Step 6: Delete Pod-2 and Create Pod-3 with Pod 2’s PVC claim

$ kubectl delete pod pod-2

Now create pod-3 with pod-2's pvc claim and validate the data in pod-3



THE END
9 ماه پیش در تاریخ 1402/08/14 منتشر شده است.
1,311 بـار بازدید شده
... بیشتر