

- Durable per-node storage that lives outside a pod so a replacement can mount the same disk and see existing data.
- A stable network identity (a predictable hostname) so other Elasticsearch nodes and clients can find a specific pod after it restarts.

- A PersistentVolume (PV) is an actual piece of storage (for example, a folder on a node or a network volume).
- A PersistentVolumeClaim (PVC) is a request for storage—think of it as a ticket that says “I need 5Gi that I can read and write from one node.” When a PV satisfies a PVC, they bind and a pod mounts the claimed volume.
- The container mounts a claim inside the Pod spec:
- The StatefulSet generates a PVC per replica using
volumeClaimTemplates:
elasticsearch-0, mounts the same claim, and finds the “USER1 logged in” document still present. This is exactly the behavior Bob wanted. Kubernetes calls this pattern a StatefulSet.


elasticsearch-0, elasticsearch-1) combined with a headless Service (clusterIP: None) so each pod has a resolvable DNS name. For external access to HTTP/transport ports you might also add a ClusterIP/NodePort or LoadBalancer service.
Bob creates a Service called elasticsearch that opens two ports: 9200 for HTTP (data and queries) and 9300 for node-to-node transport. For quick checks he exposes port 9200 via NodePort so the node maps it to 30200.

Exposing Elasticsearch with a NodePort is convenient for testing and debugging, but it opens a service port on every node. In production, prefer a LoadBalancer, an Ingress (with secure proxying), or firewall rules and ensure Elasticsearch is secured (authentication, TLS, network policies).
Recommended rule of thumb
- If losing a pod’s disk loses data you care about, use a StatefulSet with
volumeClaimTemplatesso each replica gets a durable PVC. - If other pods or clients need to discover or connect to the pod, put a Service in front for stable access.
When you need durable storage plus a stable network identity for a pod, use a StatefulSet with
volumeClaimTemplates and back it with a Service (headless for internal discovery, ClusterIP/LoadBalancer/Ingress for external access).