AWS Builder Center

Day 7: EKS Stateful vs Stateless

As part of my AWS DevOps Community Builders learning journey, Day 7 focused on understanding the difference between Stateful and Stateless applications in Amazon EKS.

As part of my AWS DevOps Community Builders learning journey, Day 7 focused on understanding the difference between Stateful and Stateless applications in Amazon EKS.
As part of my AWS DevOps Community Builders learning journey, Day 7 focused on understanding the difference between Stateful and Stateless applications in Amazon EKS.

The main focus was:
Deployment → StatefulSet → PVC → EBS → RDS
Understanding when to use stateless and stateful workloads is an important part of designing reliable Kubernetes applications.

What I Learned

  • Stateless applications
  • Stateful applications
  • Kubernetes Deployment
  • Kubernetes StatefulSet
  • Kubernetes Services
  • Headless Services
  • PersistentVolume (PV)
  • PersistentVolumeClaim (PVC)
  • AWS EBS
  • Persistent storage
  • MySQL on EKS
  • MySQL on Amazon RDS
  • EKS + RDS architecture

1. What is a Stateless Application?

A stateless application does not depend on data stored inside a specific Pod.
If a Pod fails, Kubernetes can create a replacement Pod without losing the application's persistent state.
A typical architecture looks like:
User ↓ Load Balancer ↓ Kubernetes Service ↓ Deployment ↓ Pod Pod Pod
For example:
Frontend Backend API Web application
These workloads are commonly managed using Kubernetes Deployments.

2. Kubernetes Deployment

A Deployment manages a set of replicated Pods.
Example:
apiVersion: apps/v1 kind: Deployment metadata: name: web-app spec: replicas: 3 selector: matchLabels: app: web-app template: metadata: labels: app: web-app spec: containers: - name: web-app image: nginx:latest ports: - containerPort: 80
The Deployment maintains the desired number of Pods.
If one Pod fails:
Pod 1 → Running Pod 2 → Running Pod 3 → Failed
Kubernetes can create a replacement:
Pod 1 → Running Pod 2 → Running Pod 3 → New Pod
This is one of the major benefits of stateless workloads.

3. What is a Stateful Application?

A stateful application needs to maintain data or a stable identity.
Examples include:
  • MySQL
  • PostgreSQL
  • MongoDB
  • Redis
  • Elasticsearch
These applications require persistent data.
If a database Pod is deleted, we cannot simply create a completely empty replacement Pod.
We need persistent storage.
The architecture becomes:
Application ↓ Stateful Application ↓ Persistent Storage

4. StatefulSet

Kubernetes provides StatefulSet for managing stateful workloads.
Unlike a Deployment, StatefulSet provides stable identity and ordering for Pods.
For example:
mysql-0 mysql-1 mysql-2
The Pod names remain predictable.
A simplified StatefulSet architecture is:
StatefulSet ↓ mysql-0 mysql-1 mysql-2 ↓ Persistent Storage
StatefulSets are useful when applications require stable network identities, persistent storage, and ordered deployment or scaling behavior.

5. Deployment vs StatefulSet

Deployment:
Used mainly for stateless applications.
Pods have interchangeable identities.
Example:
web-app-7d9f8c6b7d-abc12 web-app-7d9f8c6b7d-def34 web-app-7d9f8c6b7d-ghi56
StatefulSet:
Used for stateful workloads.
Pods have stable identities.
Example:
mysql-0 mysql-1 mysql-2
Simple comparison:
Deployment → Stateless
StatefulSet → Stateful
Deployment → Interchangeable Pods
StatefulSet → Stable Pod identity
Deployment → Usually no persistent identity
StatefulSet → Stable identity and storage association

6. PersistentVolume

A PersistentVolume, or PV, represents storage available to Kubernetes.
The storage exists independently from the lifecycle of an individual Pod.
Conceptually:
Pod ↓ PVC ↓ PV ↓ Storage
This allows application data to survive Pod restarts and replacements.

7. PersistentVolumeClaim

A PersistentVolumeClaim, or PVC, is a request for storage.
Instead of directly asking an application Pod to manage the underlying storage, Kubernetes uses the PVC abstraction.
The flow is:
Application Pod ↓ PersistentVolumeClaim ↓ PersistentVolume ↓ Storage
Example:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi
The PVC requests storage for the application.

8. AWS EBS with EKS

Amazon Elastic Block Store, or EBS, provides block storage that can be used by workloads running on AWS.
A simplified architecture is:
MySQL Pod ↓ PVC ↓ PersistentVolume ↓ EBS Volume
This allows database data to remain available beyond the lifecycle of the individual Pod.
EBS volumes are commonly used for workloads that require block storage.
The exact storage configuration depends on the Kubernetes StorageClass and EBS CSI driver configuration.

9. StatefulSet + PVC + EBS

A typical stateful architecture can look like:
StatefulSet ↓ mysql-0 ↓ PVC ↓ PV ↓ EBS Volume
For multiple replicas:
StatefulSet | +-- mysql-0 | | | +-- PVC | | | +-- EBS | +-- mysql-1 | +-- PVC | +-- EBS
The storage association is an important part of the stateful architecture.

10. Headless Service

Stateful applications often need stable network identities.
A Headless Service can be created using:
clusterIP: None
Example:
apiVersion: v1 kind: Service metadata: name: mysql spec: clusterIP: None selector: app: mysql ports: - port: 3306
This allows DNS-based discovery of individual StatefulSet Pods.
For example:
mysql-0 mysql-1 mysql-2
This is useful for applications that need stable Pod identity and direct Pod discovery.

11. MySQL on EKS

One option is to run MySQL directly inside Kubernetes.
The architecture can look like:
User ↓ Application ↓ Kubernetes Service ↓ MySQL StatefulSet ↓ PVC ↓ EBS
Advantages:
  • Kubernetes-native deployment
  • Full control over configuration
  • Can integrate with Kubernetes automation
  • Useful for learning and specific workloads
However, running a production database yourself also means taking responsibility for:
  • Backups
  • Upgrades
  • Replication
  • Failover
  • Monitoring
  • Storage management
  • Security
  • Disaster recovery
This is why managed database services can be attractive for production systems.

12. MySQL on Amazon RDS

Another approach is to keep the application on EKS and use Amazon RDS for MySQL.
The architecture becomes:
User ↓ ALB ↓ EKS ↓ Application Pods ↓ Amazon RDS for MySQL
In this architecture, Kubernetes manages the application layer while AWS manages the database service.
This separates application orchestration from database management.

13. EKS + RDS Architecture

A common production pattern is:
Internet ↓ Route 53 ↓ Application Load Balancer ↓ Kubernetes Ingress ↓ Kubernetes Service ↓ EKS Application Pods ↓ Amazon RDS
AWS VPC:
AWS VPC | +-- Public Subnets | | | +-- ALB | +-- Private Subnets | +-- EKS Nodes | | | +-- Application Pods | +-- RDS
The database can remain in private subnets and accept connections only from authorized application resources.

14. MySQL on EKS vs Amazon RDS

MySQL on EKS:
Application ↓ MySQL Pod ↓ PVC ↓ EBS
You manage more of the database infrastructure.
Amazon RDS:
Application ↓ EKS ↓ Private Network ↓ Amazon RDS
AWS provides a managed database service, reducing the amount of database infrastructure that you need to operate yourself.
The right choice depends on application requirements, operational expertise, cost, availability, performance, and management requirements.

15. When Should I Use Deployment?

Deployment is a good fit for workloads where Pods are interchangeable.
Examples:
  • Frontend applications
  • REST APIs
  • Backend services
  • Microservices
  • Web servers
  • Stateless workers
Example:
Deployment ↓ 3 API Pods
If one Pod fails, another Pod can replace it.

16. When Should I Use StatefulSet?

StatefulSet is designed for workloads that require stable identity and persistent storage.
Examples can include:
  • MySQL
  • PostgreSQL
  • Kafka
  • ZooKeeper
  • Elasticsearch
  • Stateful distributed systems
Example:
StatefulSet ↓ mysql-0 ↓ Persistent Storage
The stable identity and storage association are important for stateful applications.

17. Stateless vs Stateful Architecture

Stateless:
User ↓ Load Balancer ↓ Service ↓ Deployment ↓ Pods
Stateful:
Application ↓ Service ↓ StatefulSet ↓ Pod ↓ PVC ↓ EBS
Managed database approach:
Application ↓ EKS ↓ Private Network ↓ Amazon RDS

18. Why Persistence Matters

Imagine a MySQL Pod stores data only inside the container filesystem.
If the Pod is deleted:
MySQL Pod ↓ Container Storage ↓ Pod Deleted ↓ Data Lost
With persistent storage:
MySQL Pod ↓ PVC ↓ EBS ↓ Pod Deleted ↓ New Pod ↓ Persistent Data
The important concept is that the data lifecycle should not depend on the lifecycle of the application Pod.

19. Stateful Application Traffic Flow

A stateful application might have the following architecture:
User ↓ ALB ↓ Ingress ↓ Application Service ↓ Application Pods ↓ Database Service ↓ MySQL StatefulSet ↓ PVC ↓ EBS
Or, using a managed database:
User ↓ ALB ↓ Ingress ↓ Application Service ↓ Application Pods ↓ Amazon RDS

20. Security Considerations

Stateful workloads require additional attention to security.
Important areas include:
  • IAM
  • Security Groups
  • Kubernetes Secrets
  • Encryption
  • Private subnets
  • Network Policies
  • Database access control
  • Backup strategy
  • Disaster recovery
For example:
EKS Pods ↓ Security Group ↓ RDS Security Group ↓ Amazon RDS
Only the required application traffic should be allowed to reach the database.

21. Key Takeaway

The biggest lesson from Day 7 is:
Not every application should be managed the same way.
Stateless applications are generally easier to scale horizontally because their Pods are interchangeable.
Stateful applications require additional considerations such as:
  • Stable identity
  • Persistent storage
  • Data lifecycle
  • Backup
  • Recovery
  • Availability
  • Replication
A simple way to remember:
Deployment → Stateless
StatefulSet → Stateful
PVC → Storage Request
PV → Storage Resource
EBS → AWS Block Storage
RDS → Managed Database

22. Complete Architecture

A production application can combine both approaches:
INTERNET
|
↓
Route 53
|
↓
Application Load Balancer
|
↓
Kubernetes Ingress
|
↓
Kubernetes Service
|
+---------+---------+
| |
↓ ↓
Frontend Pods Backend Pods
Deployment Deployment
|
↓
Amazon RDS MySQL
Private Subnet
For a database running inside EKS:
Backend Pods | ↓ Database Service | ↓ MySQL StatefulSet | ↓ PVC | ↓ EBS Volume

My Day 7 Takeaway

Today I learned that choosing between StatefulSet and Deployment is not simply a Kubernetes configuration decision.
It depends on how the application manages data and identity.
For stateless workloads:
Deployment + Pods + Service
For stateful workloads:
StatefulSet + Service + PVC + Storage
For many production applications:
EKS + Application Pods + Amazon RDS
The key is to choose the architecture based on the application's data, availability, scalability, and operational requirements.

Connecting Day 6 and Day 7

Day 6 focused on networking:
User ↓ ALB ↓ Ingress ↓ Service ↓ Pods
Day 7 adds application state and persistence:
Application Pods ↓ StatefulSet / RDS ↓ PVC / EBS or Managed Database
Together, these concepts form an important foundation for designing production workloads on Amazon EKS.

What's Next?

Day 8: EKS Production Architecture
Topics:
  • ALB
  • EKS
  • RDS
  • VPC
  • Public Subnets
  • Private Subnets
  • Security Groups
  • NAT Gateway
  • Multi-AZ Architecture
  • High Availability
  • Production-ready EKS design
The journey continues:
Learn → Build → Secure → Automate → Deploy → Improve
#AWS #AWSCommunityBuilders #DevOps #AmazonEKS #Kubernetes #StatefulSet #Deployment #PVC #EBS #AmazonRDS #MySQL #AWSVPC #CloudComputing #DevOpsJourney #LearningInPublic
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article