Kubernetes: Resource: StatefulSet

 5th June 2021 at 4:43pm

StatefulSet 跟 ReplicaSet 很类似,都在管理一组 pod。但是 StatefulSet 是有状态的,体现在:

  • 每个 pod 有单独的、固定的存储(通过 PVC template 实现)
  • 每个 pod 有稳定的 identity,比如 hostname 在 pod 失败重启后不变
  • Scale down 更严格,一次只能 scale down 一个 pod;当前有一个 pod unhealthy 时,无法 scale down
  • 每个 pod 可以与其他 pod 通过 kube-dns 互相发现

设计 StatefulSet 可能是为了满足 分布式存储组件 的要求,比如 ZooKeeper、Consul 等。

具体的配置方法和逻辑细节再翻文档即可。