Kubernetes Operator Patterns for Stateful Workloads
Design patterns and anti-patterns for building production Kubernetes operators that manage complex stateful systems.
Elena Kowalski
Platform Engineer
February 25, 2026
14 min read
Why Operators?
Kubernetes excels at stateless workloads. But databases, message queues, and ML training jobs require domain-specific orchestration knowledge. Operators encode this knowledge as code.
The Reconciliation Loop
Every operator centers around the reconciliation pattern:
func (r DatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var db v1alpha1.Database
if err := r.Get(ctx, req.NamespacedName, &db); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
// Desired state
desired := r.buildDesiredState(&db)
// Current state
current, err := r.getCurrentState(ctx, &db)
if err != nil {
return ctrl.Result{}, err
}
// Reconcile diff
actions := r.computeActions(desired, current)
for _, action := range actions {
if err := action.Execute(ctx); err != nil {
return ctrl.Result{RequeueAfter: 30
time.Second}, err
}
}
return ctrl.Result{}, nil
}
Key Patterns
These patterns ensure your operator behaves correctly even in the face of restarts, network partitions, and concurrent modifications.