Kahibaro
Discord Login Register

Stateful applications

Understanding Stateful Applications in OpenShift

Stateful applications are those where the data and identity of the application instances matter over time. In OpenShift, this means paying special attention to how pods are named, how storage is attached, and how data survives failures, reschedules, and upgrades.

This chapter focuses on how OpenShift supports stateful workloads on top of the storage primitives already introduced elsewhere (PersistentVolumes, PersistentVolumeClaims, StorageClasses, and dynamic provisioning).

What Makes an Application Stateful?

A workload is typically considered stateful if one or more of these apply:

In contrast to stateless apps, you cannot safely scale or restart stateful apps without considering the impact on data consistency and availability.

Challenges of Running Stateful Workloads on OpenShift

Containers and Kubernetes/OpenShift were originally focused on stateless microservices. Stateful applications introduce additional challenges:

OpenShift provides patterns and APIs to address these challenges while keeping deployment as declarative as possible.

StatefulSets: Core Pattern for Stateful Workloads

For stateful workloads, the primary OpenShift/Kubernetes workload resource is the StatefulSet. While Deployments/DeploymentConfigs are suitable for stateless applications, StatefulSets add features specifically for stateful scenarios.

Key properties of a StatefulSet:

In OpenShift, you create StatefulSets using the same YAML model as Kubernetes, and they integrate with the storage model (PVs, PVCs, StorageClasses) you already learned.

Typical StatefulSet Layout

A minimal pattern for a stateful application looks like this (conceptually):

OpenShift then:

  1. Creates and attaches PVCs from the template, usually using dynamic provisioning.
  2. Ensures that pod-0 always uses pvc-0, pod-1 uses pvc-1, and so forth.
  3. Preserves these relationships across pod restarts and node changes.

Storage Design for Stateful Applications

Because stateful apps rely heavily on storage, your choice of storage backing and configuration is critical.

Access Modes and Their Impact

Different applications have different expectations about how their volumes can be used:

When defining volumeClaimTemplates in StatefulSets, ensure the requested accessModes match the application design and the capabilities of the underlying StorageClass.

Performance and Consistency Considerations

For stateful workloads, you should match the storage to the workload characteristics:

On OpenShift, this often means:

Pod Placement and Data Locality

For some stateful systems, where data is stored locally on nodes or where network topology matters, pod scheduling is important.

Common techniques:

In OpenShift, these are configured via the standard affinity and topologySpreadConstraints fields on StatefulSet pods, combined with storage classes that support topology.

Patterns for Common Stateful Applications

Relational Databases (MySQL/PostgreSQL)

Common pattern:

NoSQL Stores (Cassandra, MongoDB, etc.)

Typical needs:

File Services and Shared Storage

For workloads requiring shared file access:

Backup, Restore, and Data Protection

Stateful workloads require a strategy beyond just backing up container images and manifests.

Key aspects:

Scaling and Upgrades for Stateful Workloads

Scaling stateful apps is more complex than stateless ones.

Horizontal Scaling

When increasing replicas:

When decreasing replicas:

Rolling Updates

For stateful workloads:

Operating Stateful Apps on OpenShift

Running stateful applications successfully is as much about operational practices as it is about YAML definitions.

Recommended practices:

When Not to Use StatefulSets

Not all applications that touch storage are truly stateful in the cluster sense. You might not need a StatefulSet if:

In these cases, a Deployment or DeploymentConfig plus appropriate volumes may be simpler and more appropriate.

Summary

Stateful applications on OpenShift rely on:

Understanding these patterns allows you to confidently design and run databases, queues, and other data-intensive workloads on OpenShift in a reliable and maintainable way.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!