Skip to content

Commit 5674c2d

Browse files
Update statefulset.md
feat: add `controllerrevision` to StatefulSet
1 parent c5ce624 commit 5674c2d

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

content/en/docs/concepts/workloads/controllers/statefulset.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,99 @@ After reverting the template, you must also delete any Pods that StatefulSet had
383383
already attempted to run with the bad configuration.
384384
StatefulSet will then begin to recreate the Pods using the reverted template.
385385

386+
## Revision History and ControllerRevisions
387+
388+
**ControllerRevisions** are Kubernetes objects used by controllers like StatefulSets to track historical configuration changes. StatefulSets use ControllerRevisions to maintain a revision history, enabling rollbacks and version tracking.
389+
390+
---
391+
392+
### How ControllerRevisions Work with StatefulSets
393+
394+
When you update a StatefulSet's Pod template (`spec.template`), the StatefulSet controller:
395+
396+
1. Creates a new ControllerRevision object
397+
2. Stores a snapshot of the Pod template and metadata
398+
3. Assigns an incremental revision number
399+
400+
#### Key Properties
401+
402+
- **Name Format**: `<statefulset-name>-<revision-number>` (e.g., `webapp-2`)
403+
- **Stored Data**:
404+
- Complete Pod template configuration at time of update
405+
- Revision number (monotonically increasing integer)
406+
- Owner reference to the parent StatefulSet
407+
- **Retention**: Automatically deleted when parent StatefulSet is removed
408+
409+
---
410+
411+
### Managing Revision History
412+
413+
Control retained revisions with `.spec.revisionHistoryLimit`:
414+
415+
```yaml
416+
apiVersion: apps/v1
417+
kind: StatefulSet
418+
metadata:
419+
name: webapp
420+
spec:
421+
revisionHistoryLimit: 5 # Keep last 5 revisions
422+
# ... other spec fields ...
423+
```
424+
425+
- **Default**: 10 revisions retained if unspecified
426+
- **Cleanup**: Oldest revisions are garbage-collected when exceeding the limit
427+
428+
#### Performing Rollbacks
429+
430+
You can revert to a previous configuration using:
431+
432+
```bash
433+
# View revision history
434+
kubectl rollout history statefulset/webapp
435+
436+
# Rollback to a specific revision
437+
kubectl rollout undo statefulset/webapp --to-revision=3
438+
```
439+
440+
This will:
441+
442+
- Apply the Pod template from revision 3
443+
- Create a new ControllerRevision with an updated revision number
444+
445+
#### Inspecting ControllerRevisions
446+
447+
To view associated ControllerRevisions:
448+
449+
```bash
450+
# List all revisions for the StatefulSet
451+
kubectl get controllerrevisions -l app.kubernetes.io/name=webapp
452+
453+
# View detailed configuration of a specific revision
454+
kubectl get controllerrevision/webapp-3 -o yaml
455+
```
456+
457+
#### Best Practices
458+
459+
##### Retention Policy
460+
461+
- Set `revisionHistoryLimit` between **5–10** for most workloads
462+
- Increase only if **deep rollback history** is required
463+
464+
##### Monitoring
465+
466+
- Regularly check revisions with:
467+
468+
```bash
469+
kubectl get controllerrevisions
470+
```
471+
472+
- Alert on **rapid revision count growth**
473+
474+
##### Avoid
475+
476+
- Manual edits to ControllerRevision objects
477+
- Using revisions as a backup mechanism (use actual backup tools)
478+
- Setting `revisionHistoryLimit: 0` (disables rollback capability)
386479

387480
## PersistentVolumeClaim retention
388481

0 commit comments

Comments
 (0)