My project needs to deploy a PV
on the current master node, so this involves a resource scheduling problem. I use hostPath, so I must specify the scheduling to the current node
.
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv-redis-0
spec:
capacity:
storage: 8Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
storageClassName: local-storage-redis
persistentVolumeReclaimPolicy: Retain
local:
path: /home/lab/redis/0
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node1
But I need a common way
to implement this method for any cluster. What I’m thinking of is getting the nodeName for the current node, which by default is the same as the hostname which can be obtained with the shell’s hostname
.
But I want to do it in a more generic way to prevent it from being overridden by --hostname-override
.
I would also like to be able to make the host directory settings more generic, But kss does not seem to support relative paths
and the ${PWD}
setting
I would appreciate it if you could tell me how to solve these two problems which include resource scheduling and mount directory questions?
2
Answers
envsubst < redis.yaml | kubectl apply -f -
That's how I did it.
This is a community wiki answer posted for better visibility. Feel free to expand it.
As already mentioned by moluzhui: the Node Affinity can be used in order to get it done.
More details with some examples can be found in the linked docs.