我在库伯奈特斯创造了3 CronJobs。除了名字之外,它们的格式都是完全相同的。这些规格如下:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: test-job-1 # for others it's test-job-2 and test-job-3
namespace: cron-test
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: test-job-1 # for others it's test-job-2 and test-job-3
image: busybox
imagePullPolicy: IfNotPresent
command:
- "/bin/sh"
- "-c"
args:
- cd database-backup && touch $(date +%Y-%m-%d:%H:%M).test-job-1 && ls -la # for others the filename includes test-job-2 and test-job-3 respectively
volumeMounts:
- mountPath: "/database-backup"
name: test-job-1-pv # for others it's test-job-2-pv and test-job-3-pv
volumes:
- name: test-job-1-pv # for others it's test-job-2-pv and test-job-3-pv
persistentVolumeClaim:
claimName: test-job-1-pvc # for others it's test-job-2-pvc and test-job-3-pvc此外,还有以下持久性卷索赔和持久性卷:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-job-1-pvc # for others it's test-job-2-pvc or test-job-3-pvc
namespace: cron-test
spec:
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
resources:
requests:
storage: 1Gi
volumeName: test-job-1-pv # depending on the name it's test-job-2-pv or test-job-3-pv
storageClassName: manual
volumeMode: FilesystemapiVersion: v1
kind: PersistentVolume
metadata:
name: test-job-1-pv # for others it's test-job-2-pv and test-job-3-pv
namespace: cron-test
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/database-backup"总之,有3 CronJobs,3 PersistentVolumes和3 PersistentVolumeClaims。我可以看到,PersistentVolumeClaims和PersistentVolumes是正确绑定在一起的。所以test-job-1-pvc <-> test-job-1-pv,test-job-2-pvc <-> test-job-2-pv等等。另外,与每个PVC相关联的荚是由每个CronJob创建的相应的荚。例如,test-job-1-1609066800-95d4m <-> test-job-1-pvc等等。在让cron作业运行一段时间之后,我创建了另一个带有以下规范的荚来检查test-job-1-pvc
apiVersion: v1
kind: Pod
metadata:
name: data-access
namespace: cron-test
spec:
containers:
- name: data-access
image: busybox
command: ["sleep", "infinity"]
volumeMounts:
- name: data-access-volume
mountPath: /database-backup
volumes:
- name: data-access-volume
persistentVolumeClaim:
claimName: test-job-1-pvc只是一个一直在运行的简单的吊舱。当我使用exec进入这个吊舱并在/database-backup目录中查看时,我会看到从3 CronJobs创建的所有豆荚中创建的所有文件。
我想看到什么?
我希望只看到test-job-1创建的文件。
这会发生什么事吗?如果是这样的话,您如何才能分离PersistentVolumes以避免出现这种情况?
发布于 2020-12-27 12:47:22
我怀疑这是由PersistentVolume定义引起的:如果您真的更改了名称,那么所有卷都映射到主机上的同一个文件夹。
hostPath:
path: "/database-backup"试着给每个卷一个唯一的文件夹。
hostPath:
path: "/database-backup/volume1"https://stackoverflow.com/questions/65465823
复制相似问题