loading...
Cover image for Kubernetes Patterns : The Stateful Service Pattern

Kubernetes Patterns : The Stateful Service Pattern

ahmedat71538826 profile image Ahmed Atef Originally published at magalix.com ・1 min read

Kubernetes Patterns (8 Part Series)

1) Kubernetes Patterns : The DaemonService Pattern 2) Kubernetes Patterns : The Stateful Service Pattern 3 ... 6 3) Kubernetes Patterns : The Stateful Service Pattern 4) Kubernetes Patterns : The Stateful Service Pattern 5) Kubernetes Patterns : The Cron Job Pattern 6) Kubernetes Patterns - The Batch Job Pattern 7) Kubernetes Patterns : The Reflection Pattern 8) Kubernetes Patterns : The Ambassador Pattern

When I first learned about StatefulSets, I always wondered: why to bother creating (and using) a new controller? Why not just use a ReplicaSet or a Deployment (which uses ReplicaSets internally) to serve our stateful app? Let’s assume that you need to run a MySQL database inside your Kubernetes cluster. The database needs to run only on one instance (provided that you are not using a MySQL cluster) that serves as the data store. You can create a ReplicaSet and set the number of replicas to 1. The Pod template would have one container running the MySQL image, and a Persistent Volume Claim that points to a Persistent Volume that was provisioned firsthand. You’d also create a Service that leads to the Pod and provides a DNS name for your MySQL database.
Learn more about best practices for Stateful Pattern: https://www.magalix.com/blog/kubernetes-patterns-the-stateful-service-pattern

Discussion

markdown guide