根据你的描述,你需要的是一个持久化卷。这方面的一个示例是 NFS 持久性,您将为其定义以下 yaml。
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: $PV_NAME
namespace: $NAMESPACE
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
nfs:
path: /nfs
server: $SERVER_ADDRESS # 10.128.15.222 for instance
persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: $PVC_NAME
creationTimestamp: null
labels:
app: $PVC_NAME
namespace: $NAMESPACE
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
创建 PV 和 PVC 后,您可以将其挂载到这样的部署中。
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: $POD_NAME
labels:
app: $POD_NAME
namespace: $NAMESPACE
spec:
replicas: 1
selector:
matchLabels:
app: $POD_NAME
template:
metadata:
creationTimestamp: null
labels:
app: $POD_NAME
spec:
containers:
- name: $POD_NAME
image: $DOCKER_IMAGE
volumeMounts:
- mountPath: /testing-path
name: $VOLUME_NAME
volumes:
- name: $VOLUME_NAME
persistentVolumeClaim:
claimName: $PVC_NAME