简体   繁体   中英

Data not storing into local persistent storage kubernetes

I created Kube.netes 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.

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM