使用volumeclaimtemplate声明没有数据丢失的卷



我有一个工作负载部署应用程序,需要将其更改为statfulset

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

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

我试图改变所需的文件,但在一个地方,我需要在卷中的数据在那里,即使我移动到statfulset。在statfulset中,我们使用volumeclaimtemplate,这就是我如何保留数据并使用volumeclaimtemplate声明的地方。

注意:我将只使用一个pod

  • 如果你想在statefulset中使用现有的PVC,那么你不应该在下面提到它volumeclaimtemplate作为volumeclaimtemplate将生成新的PVC。
  • 你应该在pod spec下提到它,就像你在部署中提到的那样

例子:

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

相关内容

  • 没有找到相关文章

最新更新