Stateful deployment in kubernetes

If you deploy pod by setting “kind: Deployment“, you will lost your data when the pod restart or being deleted.

It’s not acceptable when we want to deploy storage system like Redis, Elasticsearch, in this case we need use StatefulSet.

For the concrete explanation please refer to the official documentation, StatefulSet use PVC(Persistent Volume Claim) as storage, and it will exist all the time no matter what happened to the pod.

You must specify PVC in StatefulSet’s yaml file like this:

- metadata:
  name: redis
  accessModes: [ "ReadWriteOnce" ]
  storageClassName: fast
      storage: 10Gi

Please also pay attention to PVC’s name, there’s a rule for StatefulSet and PVC name mapping which IS NOT covered by documentation.