Step 7 of 9, about 3 min
Get it ready for production
Keep the copies on different nodes, give Redis its own nodes, and let drains take one pod at a time.
What you installed runs and fails over, but it's set up to learn on, not to carry real traffic. This is what it sets and what to change first:
| This guide | For production | |
|---|---|---|
| Redis pods on different nodes | Preferred: the scheduler tries, but may share a node | Required, and spread across zones if you have them |
| Nodes only for Redis | No | Taint them, and give Redis the toleration and a node selector |
| Drains take one pod at a time | Helm: yes. YAML: no | A PodDisruptionBudget for every StatefulSet |
| Who can connect | Any pod in the cluster, with the password | Only your apps, through a NetworkPolicy |
| Memory | A request, no limit | A memory limit, and maxmemory about 25% below it |
| Encryption | None | TLS if traffic crosses a network you don't trust |
| Backups | None | Copy dump.rdb off the cluster on a schedule |
| Monitoring | None | redis_exporter: metrics.enabled: true (Bitnami), redisExporter.enabled: true (OT) |
The first three decide whether one failure stays one failure, so they come with commands below.
#Keep the copies on different nodes
A preferred (soft) anti-affinity rule only asks the scheduler to keep Redis pods apart. When a node is full or down it puts two on the same node anyway, and that node failing takes out two copies at once. A required (hard) rule never does that: a pod with nowhere valid to go waits in Pending instead.
The cost of hard: with exactly three nodes, a pod whose node is down stays Pending until the node is back, so you run on two copies meanwhile. That is the right trade for data, and a fourth node removes it.
Bitnami's preset is soft by default. In Sentinel mode all three pods are redis-node, set by the replica values:
replica:
podAntiAffinityPreset: hardIn replication mode, master and replica are separate StatefulSets and each preset only spreads its own pods: the replicas avoid each other, not the primary. Sentinel mode doesn't have that gap, which is one more reason to use it.
The OT Cluster values in the Install step already require one leader and one follower per node.
If your nodes are in more than one availability zone, also spread by zone, so losing a zone can't take a majority. Add this beside affinity in the pod spec (with Helm: replica.topologySpreadConstraints):
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: redisNetwork disks like EBS can't move between zones, so a pod in a lost zone waits for the zone to come back. The other zones keep serving.
#Give Redis its own nodes
Redis runs every command on one thread, so a noisy neighbour taking CPU or memory slows every request. On a busy cluster, keep it on nodes of its own. That takes two pieces, and each does half the job:
- A taint on the nodes keeps every pod without a matching toleration off them.
- A toleration plus a node selector on Redis lets it onto those nodes and keeps it from landing anywhere else. A toleration alone only allows; it doesn't attract.
Label and taint the nodes, here the three kind workers:
kubectl label nodes redis-lab-worker redis-lab-worker2 redis-lab-worker3 dedicated=redis
kubectl taint nodes -l dedicated=redis dedicated=redis:NoScheduleBitnami (Sentinel mode; in replication mode set the same under master too):
replica:
nodeSelector:
dedicated: redis
tolerations:
- key: dedicated
operator: Equal
value: redis
effect: NoScheduleOT Cluster: the same two keys under redisCluster.leader and redisCluster.follower.
Taint only nodes you have labelled, and keep at least three of them: everything else on the cluster can no longer run there. To undo it, kubectl taint nodes -l dedicated=redis dedicated=redis:NoSchedule-.
#Let drains take one pod at a time
Node upgrades drain nodes with kubectl drain, which evicts pods. Without a PodDisruptionBudget it can evict two Redis pods at once, on two nodes being drained together. A budget of maxUnavailable: 1 makes the second drain wait until the first pod is back and ready.
With Helm, Bitnami creates one by default (replica.pdb.create: true, one pod at a time), and the OT Cluster values in the Install step turn theirs on. With YAML, add one per StatefulSet, changing the name and app label for each:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: redis
namespace: redis
spec:
maxUnavailable: 1
selector:
matchLabels:
app: redis