Skip to content
StatefulSet vs ReplicaSet: Detailed Comparison

StatefulSet vs ReplicaSet: Detailed Comparison

This document analyzes the differences between StatefulSet and ReplicaSet, the two core workload resources for managing multiple Pods in Kubernetes.


1. Basic Concept Comparison

ResourceCore philosophyMain targetManagement tool
ReplicaSetCattle: All Pods are identical and replaceableStateless apps such as web servers and APIsDeployment
StatefulSetPet: Each Pod has its own unique identityStateful apps such as DBs and message queuesManaged directly

2. Architecture Comparison

ReplicaSet (Deployment)

Every Pod has a randomly generated name, and the Service load-balances across them as a single group.

    graph TD
    D[Deployment] --> RS[ReplicaSet]
    RS --> P1[Pod: web-abc1]
    RS --> P2[Pod: web-def2]
    RS --> P3[Pod: web-ghi3]
    P1 & P2 & P3 --- SVC[Service: LoadBalancer]
  

StatefulSet

Each Pod has an ordinal name and is mapped 1:1 to dedicated storage (PV). Individual Pods can be addressed directly through a Headless Service.

    graph TD
    SS[StatefulSet] --> P0[Pod: mysql-0]
    SS --> P1[Pod: mysql-1]
    SS --> P2[Pod: mysql-2]
    
    P0 --- PV0[(PV-0)]
    P1 --- PV1[(PV-1)]
    P2 --- PV2[(PV-2)]
    
    P0 & P1 & P2 --- HS[Headless Service: DNS]
  

3. Detailed Feature Comparison

CharacteristicReplicaSet (Deployment)StatefulSet
Pod nameRandom hash (web-abc12)Sequential number (mysql-0, mysql-1)
ScalingCreated/deleted immediately in parallelCreated sequentially from 0, deleted in reverse order
Network identityName/IP changes when a Pod is re-createdThe same name (DNS) is kept even after re-creation
Data retentionAll Pods can share a common volumeA dedicated volume is allocated and preserved for each Pod
UpdateRolling update (fast)Ordered rolling update (careful)

4. Selection Guide (Decision Tree)

Follow the flowchart below based on your application’s characteristics.

    flowchart TD
    A[Does the application store data?] -->|No| B[ReplicaSet / Deployment]
    A -->|Yes| C[Do all instances share the same data?]
    C -->|Yes| B
    C -->|No| D[Does each instance need its own unique data?]
    D -->|Yes| E[Choose StatefulSet]
    D -->|No| B
  

5. Summary

  • ReplicaSet focuses on “scaling out many replicas that perform the same function.”
  • StatefulSet focuses on “giving each replica its own stable name and data.”

Whether the application has ‘state’ is the most important criterion when choosing between them.