Closed mosoriob closed 1 month ago
POC test
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: shared-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
nodeName: hcc-nrp-shor-c6029.unl.edu
containers:
- name: container1
image: nginx
volumeMounts:
- name: shared-volume
mountPath: /shared-data
volumes:
- name: shared-volume
persistentVolumeClaim:
claimName: shared-pvc
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
spec:
nodeName: hcc-nrp-shor-c6029.unl.edu
containers:
- name: container2
image: nginx
volumeMounts:
- name: shared-volume
mountPath: /shared-data
volumes:
- name: shared-volume
persistentVolumeClaim:
claimName: shared-pvc
This YAML specification creates:
shared-pvc
with ReadWriteOnce access mode.pod1
and pod2
) that:
hcc-nrp-shor-c6029.unl.edu
shared-pvc
)/shared-data
To test this setup:
kubectl apply -f <filename>.yaml
kubectl get pods -o wide
kubectl exec pod1 -- touch /shared-data/test-file
kubectl exec pod2 -- ls /shared-data
This configuration should work because both pods are scheduled on the same node, allowing them to access the same RWO PVC. Remember that if you try to schedule these pods on different nodes, the second pod will remain in a Pending state due to the RWO access mode of the PVC.
Description
Add the ability to run a job with
ReadWriteOnce
(RWO) PVC by ensuring it is scheduled on the same node where the PVC is mounted. This feature will be configurable via thekubernetes.nodeaffinity
option in the configuration file. Ifnodeaffinity
is enabled, the Job will include a node affinity specification to ensure it runs on the correct node.Requirements
POD_NAME
will be stored in an environment variable inside the container.New methods
getNodeName: The function should retrieve the
nodeName
of the Pod using thePOD_NAME
from the environment.Example of how to obtain the node name using the Kubernetes JavaScript client:
This will return the node name of the Pod. For example:
Add Node Affinity to Job Spec: When
kubernetes.nodeaffinity
is enabled in the config file, modify the Job's Pod spec to include anodeAffinity
field, ensuring that the Job is scheduled on the same node where the PVC is mounted.Example of adding
nodeAffinity
to the Job spec using the Kubernetes JavaScript client:Configuration
kubernetes.nodeaffinity
in the configuration file to control this behavior:nodeaffinity
is enabled, add the affinity spec to the Job.Steps
POD_NAME
.kubernetes.nodeaffinity
is enabled, include thenodeAffinity
in the Job spec to schedule the Job on the same node.Notes
ReadWriteOnce
PVCs.