helm安装postgres_Kubernetes快速部署高可用PostgreSQL

本文介绍了如何在Kubernetes中使用Stolon部署高可用PostgreSQL集群。Stolon由keeper、sentinel和proxy组成,依赖etcd或consul存储集群状态。通过Helm安装Stolon,然后修改配置参数以实现外部访问。最后,通过安装PostgreSQL客户端并访问服务,验证了集群的正确设置。
摘要由CSDN通过智能技术生成

介绍在Kubernetes快速部署高可用PostgreSQL集群的方法,基于Stolon项目的工作。

Stolon是由3个部分组成的:

keeper:管理PostgreSQL实例,汇聚到由sentinel(s)提供的clusterview。

sentinel:发现并监控keeper,并且计算最理想的clusterview。

proxy:客户端的接入点。它连接到PostgreSQL的master并且强制关闭非选举产生master。

Stolon用etcd或者consul作为主要的集群状态存储,默认使用Kubernetes的存储来保存集群的状态。

第一步,安装Helm chart

# 获取项目代码,包含一个Helm Chart及其默认参数。

$ git clone https://github.com/lwolf/stolon-chart

# 安装到命名空间stolon,helm chart名称为postgresql。

$ cd stolon-chart

$ helm install ./stolon --name postgresql --namespace stolon

此时,打开Dashboard面板,应该可以看到命名空间stolon下的运行pod和服务等资源。

第二步,修改配置参数

编辑stolon的服务,修改网络地址类型为NodePort(端口号30900),以便外部访问。

kubeedit svc/waxen-seal-stolon-proxy -n stolon

修改后的配置文件如下:

#supermap@podc01:~/openthings/$kubectl get svc/waxen-seal-stolon-proxy -n stolon -o yaml

apiVersion: v1

kind: Service

metadata:

creationTimestamp: "2018-12-25T07:59:48Z"

labels:

app: waxen-seal-stolon-proxy

chart: stolon-0.7.0

component: stolon-proxy

heritage: Tiller

release: waxen-seal

name: waxen-seal-stolon-proxy

namespace: stolon

resourceVersion: "596639"

selfLink: /api/v1/namespaces/stolon/services/waxen-seal-stolon-proxy

uid: 0d0ef0b1-081b-11e9-822a-7085c2a625da

spec:

clusterIP: 10.103.227.204

externalTrafficPolicy: Cluster

ports:

- nodePort: 30900

port: 5432

protocol: TCP

targetPort: 5432

selector:

app: waxen-seal-stolon-proxy

chart: stolon-0.7.0

component: stolon-proxy

release: waxen-seal

stolon-cluster: waxen-seal-stolon

sessionAffinity: None

type: NodePort

status:

loadBalancer: {}

第三步,安装客户端并访问服务

获取代理服务服务的登录密码(用户名为stolon):

PGPASSWORD=$(kubectl get secret --namespace stolon waxen-seal-stolon -o jsonpath="{.data.pg_su_password}" | base64 --decode; echo)

echo $PGPASSWORD

宿主机上,安装postgresql的客户端:

sudo apt install postgresql-client-common postgresql-client

测试一下(创建表、添加记录、查询记录):

#psql --host --port 30900 postgres -U stolon -W

psql --host localhost --port 30900 postgres -U stolon -W

#输入上面获得的登录密码,回车。

postgres=# create table test (id int primary key not null,

value text not null);

CREATE TABLE

postgres=# insert into test values (1, 'value1');

INSERT 0 1

postgres=# select * from test;

id | value

---- --------

1 | value1

(1 row)

完毕。

更多参考:

MySQL, Vitess: Scaling MySQL with Sugu Sougoumarane

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值