简体   繁体   English

数据未存储到本地持久存储 kube.netes

[英]Data not storing into local persistent storage kubernetes

I created Kube.netes persistent volume and claim & used them in deployment file.我创建了 Kube.netes 持久卷并在部署文件中声明并使用了它们。

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.我希望数据存储在我在本地创建的 pv 中。

Below is my PVC.下面是我的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下面是我的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.我的数据仍然在 pod 中。

which i want to be go inside pv.我想在 pv 中成为 go。

I think you misunderstood the concept of pv and pvc.我认为你误解了 pv 和 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. PV 只是集群范围的存储,而 pvc 是 pod 可以用来存储数据并在需要时声明它的存储。 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.当您将 PVC 添加到 pod 时,您的 pod 生成的任何数据都会存储在 PVC 上,这意味着无论您的 pod 被杀死还是重新创建,新的 pod 都将拥有所有数据。

Your deployment should refer to this PVC:您的部署应参考此 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!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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