Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

persistentvolumeclaim not found in kubernetes

Currently i try to implement PersistentVolume in my yaml file . I read a lot of documentation on internet and i dont understand why when i go to the dashboard pod i've this message

persistentvolumeclaim "karaf-conf" not found

pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: karafpod
spec:
  containers:
  - name: karaf
    image: xxx/karaf:ids-1.1.0
    volumeMounts:
    - name: karaf-conf-storage
      mountPath: "/apps/karaf/etc"
  volumes:
    - name: karaf-conf-storage
      persistentVolumeClaim:
        claimName: karaf-conf-claim

PersistentVolumeClaimKaraf.yml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: karaf-conf-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi

PersistentVolume.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: karaf-conf
  labels:
    type: local
spec:
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/apps/karaf/etc"

You will find below the result of the command kubectl get pv

NAME                             CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS        CLAIM                         STORAGECLASS   REASON    AGE
karaf-conf                    100Mi      RWO            Retain           Terminating   default/karaf-conf-claim                            17h
karaf-conf-persistentvolume   100Mi      RWO            Retain           Released      default/karaf-conf                                  1h

kubectl get pvc

NAME                  STATUS        VOLUME          CAPACITY   ACCESS MODES   STORAGECLASS   AGE
karaf-conf-claim   Terminating   karaf-conf   10Mi       RWO            manual         17h
like image 232
morla Avatar asked Jun 27 '18 10:06

morla


People also ask

What is persistent volume claim in Kubernetes?

A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory).

What is persistent volume and persistent volume claim in Kubernetes?

A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by server/storage/cluster administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like node. A PersistentVolumeClaim (PVC) is a request for storage by a user which can be attained from PV.


1 Answers

With hostPath, you don't need PersistentVolume or PersistentVolumeClaim objects, so this might be easier depending on your need:

# file: pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: karafpod
spec:
  containers:
  - name: karaf
    image: xxx/karaf:ids-1.1.0
    volumeMounts:
    - name: karaf-conf-storage
      mountPath: "/apps/karaf/etc"  # Path mounted in container

  # Use hostPath here
  volumes:
    - name: karaf-conf-storage
      hostPath:
        path: "/apps/karaf/etc" # Path from the host

Then delete the other two .yaml files PersistentVolumeClaimKaraf.yml and PersistentVolume.yml

For official documentation, see: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath

Edit: Noticed that spec.containers.VolumeMounts.mountPath and spec.containers.volumes.hostPath.path from the original post were the same, so added comments in yaml to clarify purpose of each.

like image 125
Iain H. Avatar answered Sep 20 '22 07:09

Iain H.