Host specific volumes in Kubernetes manifests

3/8/2017

I am fairly sure this isn't possible, but I wanted to check.

I am using Kubernetes stateful sets, so my hosts get obvious hostnames.

I'd like them to provision a hostPath mount that is mapped to their hostname.

An example helm chart that I'm using might look like this:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: app
  namespace: '{{ .Values.name }}'
  labels:
    chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}'
spec:
  serviceName: "app"
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: app
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}/{{ .Values.image.version}}"
        imagePullPolicy: '{{ .Values.image.pullPolicy }}'
        env:
        - name: POD_NAME
        valueFrom:
            fieldRef:
              fieldPath: metadata.name
        ports:
        - containerPort: {{ .Values.baseport | add 80 }}
          name: app
        volumeMounts:
        - mountPath: /NAS/$(POD_NAME)
          name: store
          readOnly: true
      volumes:
        - name: store
          hostPath:
            path: /NAS/$(POD_NAME)

Essentially, instead of hardcoding a volume, I'd like to have some kind of dynamic variable as the path. I don't mind using helm or the downward API for this, but ideally it would work when I scale the stateful set outwards.

Is there any way of doing this? All my docs reading seems to think it's not... :(

-- jaxxstorm
kubernetes
kubernetes-helm

0 Answers