<p>In Kubernetes is it possible to add <code>hostPath</code> storage in Statefulset. If so, can someone help me with some example?</p>

Dinesh
<p>Yes but it is definitely for testing purposes.</p>

<p>First you need to create as many Persistent Volume as you need</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: hp-pv-001
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/data01"

kind: PersistentVolume
apiVersion: v1
metadata:
  name: hp-pv-002
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/data02"
...
</code></pre>

<p>Afterwards, add this VolumeClaimsTemplate to your Statefulset</p>

<pre><code>volumeClaimTemplates:
- metadata:
    name: my-hostpath-volume
  spec:
    storageClassName: manual
    accessModes: ["ReadWriteOnce"]
    resources:
      requests:
        storage: 5Gi
    selector:
      matchLabels:
        type: local
</code></pre>

<p>Another solution is using the <a href="https://github.com/kubernetes-incubator/external-storage/blob/master/docs/README.md" rel="noreferrer">hostpath dynamic provisioner</a>. You do not have to create the PV bin advance but this remains a "proof-of-concept solution" as well and you will have to build and deploy the provisioner in your cluster.</p>
