<p>My project needs to deploy a <code>PV</code> on the current master node, so this involves a <strong>resource scheduling</strong> problem. I use hostPath, so I must specify the scheduling to the <code>current node</code>.</p>
<pre><code>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
</code></pre>
<p>But I need a <code>common way</code> 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 <code>hostname</code>.</p>
<p>But I want to do it in a more generic way to prevent it from being overridden by <code>--hostname-override</code>.</p>
<p>I would also like to be able to make the <strong>host directory</strong> settings more generic, But kss does not seem to support <code>relative paths</code> and the <code>${PWD}</code> setting</p>
<p>I would appreciate it if you could tell me how to solve these two problems which include <strong>resource scheduling and mount directory</strong> questions?</p>

moluzhui
<p><code>envsubst &lt; redis.yaml | kubectl apply -f -</code></p>
<pre><code># redis.yaml
apiVersion: apps/v1
kind: List
items:
- kind: StorageClass
  apiVersion: storage.k8s.io/v1
  metadata:
    name: local-storage-redis
    namespace: test-system
  provisioner: kubernetes.io/no-provisioner
  volumeBindingMode: WaitForFirstConsumer

- apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: local-pv-redis-0
    namespace: test-system
  spec:
    capacity:
      storage: 8Gi
    volumeMode: Filesystem
    accessModes:
    - ReadWriteOnce
    storageClassName: local-storage-redis
    persistentVolumeReclaimPolicy: Retain
    local:
      path: ${PWD}/redis-0
    nodeAffinity:
      required:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - ${HOST_NAME}
</code></pre>
<p>That's how I did it.</p>
