Skip to content

Commit f6fa32f

Browse files
authored
Merge pull request #52353 from husnialhamdani/patch-1
Add controller revision section to StatefulSet concept page
2 parents 147d024 + 4adddde commit f6fa32f

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

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

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

387476
## PersistentVolumeClaim retention
388477

0 commit comments

Comments
 (0)