k8s中使用cloudnativepg部署postgresql集群,主从故障自动切换
部署sc,我这里部署的local-path-provisioner
将sc设置为默认
kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'部署cloudnativepg
部署postgresql
在k8s集群中用来部署postgresql的节点打上污点2台或以上,如果不指定哪个节点单独部署postgresql,直接执行下一步
kubectl taint node nodename node-role.kubernetes.io/postgres=run:NoSchedule在k8s集群中用来部署postgresql的节点打上标签2台或以上
kubectl label node nodename node-role.kubernetes.io/postgres=run部署postgresql,instances: 2表示部署一主一从,根据自己的环境更改,storage、shared_buffers、max_connections 根据自己的环境更改
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-postgres
spec:
instances: 2
postgresql:
parameters:
shared_buffers: "256MB"
max_connections: "4000"
storage:
size: 1000Gi
imageName: ghcr.io/cloudnative-pg/postgresql:16.13
imagePullPolicy: IfNotPresent
affinity:
enablePodAntiAffinity: true
topologyKey: kubernetes.io/hostname
podAntiAffinityType: required
nodeSelector:
node-role.kubernetes.io/postgres: run
tolerations:
- key: node-role.kubernetes.io/postgres
operator: Equal
value: run
effect: NoSchedule
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 运维小白
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果

