简体   繁体   English

在 statefulset 中重新启动 pod 时创建一个新卷

[英]Create a new volume when pod restart in a statefulset

I'm using azure aks to create a statefulset with volume using azure disk provisioner.我正在使用 azure 使用 azure 磁盘配置器创建一个带有卷的状态集。 I'm trying to find a way to write my statefulset YAML file in a way that when a pod restarts, it will get a new Volume and the old volume will be deleted.我正在尝试找到一种方法来编写我的statefulset YAML 文件,这样当 pod 重新启动时,它将获得一个新的,而旧的卷将被删除。

I know I can delete volumes manually, but is there any ways to tell Kubernetes to do this via statefulset yaml?我知道我可以手动删除卷,但是有什么方法可以告诉 Kubernetes 通过 statefulset yaml 执行此操作?

Here is my Yaml:这是我的 Yaml:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: janusgraph
  labels:
    app: janusgraph
spec:
...
...
  template:
    metadata:
      labels:
        app: janusgraph
    spec:
      containers:
        - name: janusgraph
...
...
          volumeMounts:
            - name: data
              mountPath: /var/lib/janusgraph
          livenessProbe:
            httpGet:
              port: 8182
              path: ?gremlin=g.V(123).count()
            initialDelaySeconds: 120
            periodSeconds: 10
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: ["ReadWriteOnce"]
        storageClassName: "default"
        resources:
          requests:
            storage: 7Gi

If you want your data to be deleted when the pod restarts, you can use an ephemeral volume like EmptyDir .如果您希望在 pod 重新启动时删除您的数据,您可以使用像EmptyDir这样的临时卷。

When a Pod is removed/restarted for any reason, the data in the emptyDir is deleted forever.当 Pod 因任何原因被移除/重启时,emptyDir 中的数据将被永久删除。

Sample:样本:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 3 # by default is 1
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
      volumes:
      - name: www
        emptyDir: {}

NB: By default, emptyDir volumes are stored on whatever medium is backing the node - that might be disk or SSD or network storage, depending on your environment.注意:默认情况下, emptyDir卷存储在支持节点的任何介质上——可能是磁盘、SSD 或网络存储,具体取决于您的环境。 However, you can set the emptyDir.medium field to "Memory" to tell Kubernetes to mount a tmpfs (RAM-backed filesystem) for you instead.但是,您可以将emptyDir.medium字段设置为“内存”,以告诉 Kubernetes 为您安装tmpfs (RAM 支持的文件系统)。

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

相关问题 kubernetes timescaledb statefulset:吊舱休闲丢失的更改 - kubernetes timescaledb statefulset: Changes lost on pod recreation 容器环境变量发生变化时如何强制重启pod - How to force restart pod when there is change in container environment variable 我们如何创建基于天蓝色磁盘的持久卷声明并从 Kubernetes 中的 POD 使用它们? - How can we create azure-disk based persistent volume claim and use them from a POD in Kubernetes? 重启 pod 依赖于健康检查 - Restart pod depend on health check 无法使用 statefulset 和 sidecar 为 mongodb 创建只读副本 - unable to create read replica for mongodb with statefulset and sidecar 将新卷附加到持久卷声明 (Kubernetes) - Attaching New Volume to Persistent Volume Claim (Kubernetes) 无法使用 Azure 文件配置器将卷安装到 Kubernetes 中的 pod - Cannot mount volume to pod in Kubernetes using Azure file provisioner AKS POD 新 IP 的应用网关 - Application Gateway to pickup new IP of AKS POD 如何在从 Azure Key Vault 更新机密时自动重新启动 pod/部署 - How to auto restart pod/Deployment on update of a secret from Azure Key Vault 创建新服务名称空间时未列出Azure订阅 - Azure no subscription listed when create new service namespace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM