简体   繁体   English

使用volumeclaimtemplate声明卷而不丢失数据

[英]claim volume without data loss using volumeclaimtemplate

I have a application of workload deployment and need to change it to statefulset我有一个工作负载部署的应用程序,需要将其更改为 statefulset

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
  labels:
    app: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: app
        image: nginx:1.14.2
        ports:
        - containerPort: 80 
        volumeMounts:
        - name: data
          subPath: app/log
          mountPath: /opt/app/log
      volumes:
      - name: data
        peristentVolumeClaim:
           claimName: pv-app-claim

PV光伏

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-app
  labels:
    pv: app
spec:
  storageClassName: "default"
  capacity:
    storage: 8Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeclaimPolicy: Retain
  nfs:
     server: someIP
     path: "/somepath"

PVC PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-app-claim
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 8Gi
  selector:
    matchLabels:
        pv: app

I have tried to change the required file but struck in a place where I need the data in the volume to be there even when I'm moving to statefulset.我试图更改所需的文件,但在我需要卷中的数据存在的地方,即使我正在移动到 statefulset。 In statefulset we use volumeclaimtemplate this is where i'm struck how to retain the data and claim with volumeclaimtemplate.在 statefulset 中,我们使用 volumeclaimtemplate,这是我对如何使用 volumeclaimtemplate 保留数据和声明感到震惊的地方。

Note: I'm going to use only one pod注意:我将只使用一个 pod

  • If you want to use existing PVC in statefulset then you should not mention it under volumeclaimtemplate as volumeclaimtemplate will create a new PVC .如果你想在 statefulset 中使用现有的 PVC,那么你不应该在volumeclaimtemplate下提及它,因为volumeclaimtemplate会创建一个新的 PVC。
  • You should mention it under pod spec just like you mention in a deployment您应该在pod spec下提及它,就像您在部署中提及的那样

Example:例子:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web1
spec:
  selector:
    matchLabels:
      app: nginx
  serviceName: "nginx"
  replicas: 1 
  template:
    metadata:
      labels:
        app: nginx 
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx1
        imagePullPolicy: IfNotPresent
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web1
        volumeMounts:
        - name: www1
          mountPath: /usr/share/nginx/html
      volumes:
      - name: www1
        peristentVolumeClaim:
           claimName: pv-app-claim

暂无
暂无

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

相关问题 在dockerfile中创建一个没有Kubernetes中的持久卷(声明)的卷? - Creating a volume in a dockerfile without a persistent volume (claim) in Kubernetes? 在 Kubernetes 内使用 PVC 加密 EBS 卷而不会丢失数据 - Encrypt EBS volume with PVC without data loss inside Kubernetes 是否需要创建持久化卷 object 然后使用持久化卷声明来声明它,或者我们可以直接使用存储 class - Is it necessary to create persitent volume object and then claim it using persistent volume claim or we can directly use storage class 如何将一个持久卷声明的数据与另一个隔离 - How to isolate data of one persistent volume claim from another 如何在 Kubernetes 持久卷中声明和配置 Bitnami Docker 话语数据? - How to claim & configure Bitnami Docker Discourse data in Kubernetes Persistent volume? Kube.netes Persistent Volume Claim 不保存数据 - Kubernetes Persistent Volume Claim doesn't save the data mongodb 微服务 k8 持久卷声明不持久数据 - mongodb microservice k8 persistent volume claim not persisting data 如何在 GKE 中查找哪个 pod 正在使用 Persistent Volume Claim - How to find which pod is using a Persistent Volume Claim in GKE 使用 Persistent Volume Claim 时是否必须显式创建 Persistent Volume? - Do I have to explicitly create Persistent Volume when I am using Persistent Volume Claim? POD 崩溃时持久卷声明中的容器数据 - Container Data in Persistent Volume Claim when POD crashes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM