While you can use Volumes to persists data for individual Pods, this won't work for our StatefulSet. This is because each of the replica Elasticsearch nodes will try to write to the same files at the same time; only one will succeed, the others will fail. If you tried, the following hanged state is what you'll encounter:
$ kubectl get podsNAME READY STATUS RESTARTSelasticsearch-0 1/1 Running 0 elasticsearch-1 0/1 CrashLoopBackOff 7 elasticsearch-2 0/1 CrashLoopBackOff 7
If we use kubectl logs to inspect one of the failing Pods, you'll see the following error message:
$ kubectl logs elasticsearch-1[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException: ...