DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Statefulness on K8s

原文链接

This concept is vastly different than the idea of containers being fast and lightweight and easy to deploy anywhere needed at a moments notice. It’s for this reason that persistent state was purposefully left out of container specs, which opted instead for storage plugins; shifting the responsibility of managing persistent state to another party(container不带storage,而以plugins的方式来进行补充)

There are two key features of an application that require persistent state:

  • the need to persist data beyondapplication outages and restarts
  • and the need to manage application state acrossthe same outages and restarts.

Kubernetes Persistent Volumesand Persistent Volume Claimsprovide a way to abstract the details of how storage is provisioned from how it is consumed.

The .spec.storageClassName can be used to classify the PV as a certain class of storage, which can be leveraged by PVCs to specify a specific class of storage to claim.

1
2
3
4
5
6
7
8
9
10
11
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
spec:
storageClassName: mysc
accessModes:
ReadWriteOnce
resources:
requests:
storage: 8Gi