Create a Redis StatefulSet with Stable Pod Identities and Persistent Storage
Scenario
You are setting up a distributed caching system in namespace coral. The system requires a StatefulSet so that each cache node gets a stable identity and its own dedicated storage. A Headless Service is required so that each Pod is individually addressable by DNS.
Task
In namespace coral, create a Headless Service named cache-headless with clusterIP: None, selector role: cache, and port 6379.
Then create a StatefulSet named cache-nodes with the following configuration:
4replicas ofredis:alpine- container named
cacheon port6379 volumeClaimTemplatenamedcache-storagerequesting128Mistorage withstorageClassName: local-pathserviceNameset tocache-headless.
Confirm the Pods come up with sequential names cache-nodes-0 through cache-nodes-3.
Ensure all StatefulSet Pods are running.
Hint 1
A StatefulSet requires a Headless Service (clusterIP: None) to provide stable network identities for its Pods.
The serviceName in the StatefulSet must match this Service, and each Pod receives a predictable DNS name in the form <pod-name>.<service-name>.<namespace>.svc.cluster.local.
Create the Headless Service before the StatefulSet, since the StatefulSet references it by name.
Use volumeClaimTemplates so that each Pod automatically gets its own dedicated PersistentVolumeClaim with persistent storage.
See the official docs: StatefulSets