CFN Cloud
Cloud Future New Life
en zh
2025-10-10 · 0 views

StatefulSet Basics

Provide stable identity and storage for stateful workloads.

StatefulSet is built for databases and queues. The key idea is stable identity plus stable storage.

Typical features

  • Fixed Pod names (like mysql-0)
  • One PVC per Pod
  • Ordered startup and rolling updates

Core snippet

spec:
  serviceName: mysql
  replicas: 3
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi

Tips

  • Pair with a Headless Service
  • Validate with a single replica before scaling

Practical notes

  • Start with a quick inventory: kubectl get nodes, kubectl get pods -A, and kubectl get events -A.
  • Compare desired vs. observed state; kubectl describe usually explains drift or failed controllers.
  • Keep names, labels, and selectors consistent so Services and controllers can find Pods.

Quick checklist

  • The resource matches the intent you described in YAML.
  • Namespaces, RBAC, and images are correct for the target environment.
  • Health checks and logs are in place before promotion.

References