Redis › Redis with Docker & Kubernetes
How do you deploy Redis on Kubernetes using a StatefulSet rather than a regular Deployment, and why is this distinction important?
IntermediateAnswer
A StatefulSet is used instead of a regular Deployment because Redis needs stable network identities and persistent storage tied to each specific pod, ensuring that if a pod restarts, it reconnects to the same underlying storage it was using before, which is essential for maintaining data consistency and correctly functioning replication relationships.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
serviceName: redis
replicas: 3
volumeClaimTemplates:
- metadata:
name: redis-dataReal-world example A team deploying a Redis Cluster on Kubernetes uses a StatefulSet specifically because each Redis node needs to consistently reconnect to its own dedicated persistent volume, something a regular Deployment does not reliably guarantee.