I have a set of Kubernetes cronjobs that I want to run. The Persistent Volume Claim is ReadWriteOnce. There will be one job which updates the data on the volume, and the other jobs will read the data. The pvc can only be bound to one node at a time, but my understanding (this may be wrong) is that other pods can mount it read-only provided they are scheduled on the correct node. (Obviously only one pod can mount it read/write.)
I see that I can schedule two pods on the same node using podAffinity, but is there a way to use affinity to select the node that has the pvc attached? Or is it possible in GKE to do this? My claim looks like this:
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-persistent-volume
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: standard
You should be able to do this using Pod Affinity with labels and a topologyKey set to kubernetes.io/hostname. Your affinity stanza would look something like:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- mycronjob
topologyKey: kubernetes.io/hostname
which would schedule jobs with label app=mycronjob on the same node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With