Site icon i2tutorials

Kubernetes – Volumes

Kubernetes – Volumes

 

Kubernetes has different types of volumes, and the type determines how and what the volume contains.

Volumes were present in Docker, but they were very much limited to pods. The volume would disappear as soon as the pod died.

Meanwhile, Kubernetes doesn’t limit volumes to containers. A key advantage of Kubernetes volume is that it supports different kinds of storage simultaneously. It supports any or all containers inside the pod.

Types of Kubernetes Volume

Here are some of the most popular Kubernetes volumes

Persistent Volume and Persistent Volume Claim

Persistent Volume (PV) − A piece of network storage that has been provisioned by the cluster administrator. It is independent of any individual pod using it.

Persistent Volume Claim (PVC) − Kubernetes uses PVC storage for pods. Users don’t need to know about the provisioning. Pods and claims must be in the same namespace.

Creating Persistent Volume

kind: PersistentVolume ---------> 1
apiVersion: v1
metadata:
   name: pv1 ------------------> 2
   labels:
      type: local
spec:
   capacity: -----------------------> 3
      storage: 10Gi ----------------------> 4
   accessModes:
      - ReadWriteOnce -------------------> 5
      hostPath:
         path: "/tmp/data01" --------------------------> 6

The above code defines −

Creating PV

$ kubectl create –f local.yaml

persistentvolume “pv1” created

Checking PV

$ kubectl get pv

NAME        CAPACITY      ACCESSMODES       STATUS       CLAIM      REASON     AGE

pv1               10Gi            RWO                         Available                            14s

Describing PV

$ kubectl describe pv pv1

Creating Persistent Volume Claim

kind: PersistentVolumeClaim --------------> 1
apiVersion: v1
metadata:
   name: myclaim-1 --------------------> 2
spec:
   accessModes:
      - ReadWriteOnce ------------------------> 3
   resources:
      requests:
         storage: 3Gi ---------------------> 4

The above code defines −

Creating PVC

$ kubectl create –f myclaim-1
persistentvolumeclaim "myclaim-1" created

Getting Details About PVC

$ kubectl get pvc
NAME        STATUS   VOLUME   CAPACITY   ACCESSMODES   AGE
myclaim-1   Bound    pv1     10Gi         RWO       7s

Describe PVC

$ kubectl describe pv pv0001

Using PV and PVC with POD

kind: Pod
apiVersion: v1
metadata:
   name: mypod
   labels:
      name: frontendhttp
spec:
   containers:
   - name: myfrontend
      image: nginx
      ports:
      - containerPort: 80
         name: "http-server"
      volumeMounts: ----------------------------> 1
      - mountPath: "/usr/share/tomcat/html"
         name: mypd
   volumes: -----------------------> 2
      - name: mypd
         persistentVolumeClaim: ------------------------->3
         claimName: myclaim-1

The above code defines −

 

Exit mobile version