-1

I created Kubernetes persistent volume and claim & used them in deployment file.

Deployment working fine. But error i am having is data is still storing inside containers.

i want data to be store in pv which i created on local.

Below is my PVC.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: admin-pvc
  labels:
    app: data
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 2Gi
  selector:
    matchLabels:
      type: local

Below is my pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: local-storage
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/data"

still my data is going inside pod.

which i want to be go inside pv.

Dharmendra jha
  • 101
  • 2
  • 11

2 Answers2

0

I think you misunderstood the concept of pv and pvc. PV is just the clusterwide storage and pvc is the storage that can be used by pod to store the data and claim it whenever it needs. When you add PVC to pod then whatever data your pod generates it get's stored on PVC which means no matter your pod get's killed or recreated the new pod will have all the data.

Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42
0

Your deployment should refer to this PVC:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    name: something
  name: something
spec:
  replicas: 1
  selector:
    matchLabels:
      name: something
  strategy:
    type: Recreate
  template:
    spec:
      containers:
        - image: something/something
          volumeMounts:
            - name: your-volume-mount
              mountPath: /some/path/in/your/container
      restartPolicy: Always
      dnsPolicy: ClusterFirst
      volumes:
        - name: your-volume-mount
          persistentVolumeClaim:
            claimName: admin-pvc  # here it is!
Sam
  • 5,375
  • 2
  • 45
  • 54