Middle
In Kubernetes, how to deploy a database in three replicas, each with its own storage? Which object to use and why? How to natively implement canary deployment — first update one pod out of ten, then only by decision?
sobes.tech AI
Answer from AI
To deploy a database in Kubernetes with three replicas, each with its own storage, you should use the StatefulSet object.
Why StatefulSet?
- StatefulSet guarantees unique and stable pod identifiers (names).
- Each pod gets its persistent storage through PersistentVolumeClaim, which is important for databases.
- Ensures ordered creation, updating, and deletion of pods.
Example: each of the three pods will have its own PVC, providing separate storage.
For native canary deployment in Kubernetes, you can use the RollingUpdate strategy with the maxUnavailable and maxSurge parameters, but to update only one pod out of ten initially, and then proceed based on decision, you need to apply Pause and Resume updates or use Manual Rollout.
Approach example:
- Start updating with one pod, specifying
maxUnavailable: 1. - After checking the status and making a decision, continue updating the remaining pods manually with the command:
kubectl rollout pause statefulset/your-db
# Check status
kubectl rollout resume statefulset/your-db
Thus, you can control the update process, stopping and resuming it as needed, which implements a canary deployment with manual confirmation after the first update.