[英]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.