當你開始把應用程式搬進 Kubernetes 的世界,你會很快發現:Stateless 很好搞,Deployment + Service + HPA 就能隨便彈性伸縮。
但一旦牽涉到 Stateful(有狀態服務),像是 PostgreSQL 這樣的資料庫,麻煩就來了。
kubectl apply -f cluster.yaml
就可以自動建好 Primary + Replica
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
name: hippo
spec:
instances:
- replicas: 3
backups:
pgbackrest:
repos:
- name: repo1
volume:
volumeClaimSpec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi